JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.util;
/**
* Helper class used to encapsulate details of name mangling, transforming
* of names using different strategies (prefixes, suffixes).
* Default implementation is "no-operation" (aka identity transformation).
*/
public abstract class NameTransformer
{
/**
* Singleton "no-operation" transformer which simply returns given
* name as is. Used commonly as placeholder or marker.
*/
public final static NameTransformer NOP = new NopTransformer();
protected final static class NopTransformer
extends NameTransformer
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
@Override
public String transform(String name) {
return name;
}
@Override
public String reverse(String transformed) {
// identity transformation is always reversible:
return transformed;
}
}
protected NameTransformer() { }
/**
* Factory method for constructing a simple transformer based on
* prefix and/or suffix.
*/
public static NameTransformer simpleTransformer(final String prefix, final String suffix)
{
boolean hasPrefix = (prefix != null) && (prefix.length() > 0);
boolean hasSuffix = (suffix != null) && (suffix.length() > 0);
if (hasPrefix) {
if (hasSuffix) {
return new NameTransformer() {
@Override
public String transform(String name) { return prefix + name + suffix; }
@Override
public String reverse(String transformed) {
if (transformed.startsWith(prefix)) {
String str = transformed.substring(prefix.length());
if (str.endsWith(suffix)) {
return str.substring(0, str.length() - suffix.length());
}
}
return null;
}
@Override
public String toString() { return "[PreAndSuffixTransformer('"+prefix+"','"+suffix+"')]"; }
};
}
return new NameTransformer() {
@Override
public String transform(String name) { return prefix + name; }
@Override
public String reverse(String transformed) {
if (transformed.startsWith(prefix)) {
return transformed.substring(prefix.length());
}
return null;
}
@Override
public String toString() { return "[PrefixTransformer('"+prefix+"')]"; }
};
}
if (hasSuffix) {
return new NameTransformer() {
@Override
public String transform(String name) { return name + suffix; }
@Override
public String reverse(String transformed) {
if (transformed.endsWith(suffix)) {
return transformed.substring(0, transformed.length() - suffix.length());
}
return null;
}
@Override
public String toString() { return "[SuffixTransformer('"+suffix+"')]"; }
};
}
return NOP;
}
/**
* Method that constructs transformer that applies given transformers
* as a sequence; essentially combines separate transform operations
* into one logical transformation.
*/
public static NameTransformer chainedTransformer(NameTransformer t1, NameTransformer t2)
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS> {
return new Chained(t1, t2);
}
/**
* Method called when (forward) transformation is needed.
*/
public abstract String transform(String name);
/**
* Method called when reversal of transformation is needed; should return
* null if this is not possible, that is, given name can not have been
* result of calling {@link #transform} of this object.
*/
public abstract String reverse(String transformed);
public static class Chained extends NameTransformer
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected final NameTransformer _t1, _t2;
public Chained(NameTransformer t1, NameTransformer t2) {
_t1 = t1;
_t2 = t2;
}
@Override
public String transform(String name) {
return _t1.transform(_t2.transform(name));
}
@Override
public String reverse(String transformed) {
transformed = _t1.reverse(transformed);
if (transformed != null) {
transformed = _t2.reverse(transformed);
}
return transformed;
}
@Override
public String toString() { return "[ChainedTransformer("+_t1+", "+_t2+")]"; }
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
@SuppressWarnings("serial")
public class StdKeySerializers
{
protected final static JsonSerializer<Object> DEFAULT_KEY_SERIALIZER = new StdKeySerializer();
protected final static JsonSerializer<Object> DEFAULT_STRING_SERIALIZER = new StringKeySerializer();
private StdKeySerializers() { }
/**
* @param config Serialization configuration in use, may be needed in choosing
* serializer to use
* @param rawKeyType Type of key values to serialize
* @param useDefault If no match is found, should we return fallback deserializer
* (true), or null (false)?
*/
public static JsonSerializer<Object> getStdKeySerializer(SerializationConfig config,
Class<?> rawKeyType, boolean useDefault)
{
if (rawKeyType != null) {
if (rawKeyType == String.class) {
return DEFAULT_STRING_SERIALIZER;
}
if (rawKeyType == Object.class || rawKeyType.isPrimitive()
|| Number.class.isAssignableFrom(rawKeyType)) {
return DEFAULT_KEY_SERIALIZER;
}
if (rawKeyType == Class.class) {
return new Default(Default.TYPE_CLASS, rawKeyType);
}
if (Date.class.isAssignableFrom(rawKeyType)) {
return new Default(Default.TYPE_DATE, rawKeyType);
}
if (Calendar.class.isAssignableFrom(rawKeyType)) {
return new Default(Default.TYPE_CALENDAR, rawKeyType);
}
// other types we know convert properly with 'toString()'?
if (rawKeyType == java.util.UUID.class) {
return new Default(Default.TYPE_TO_STRING, rawKeyType);
}
}
return useDefault ? DEFAULT_KEY_SERIALIZER : null;
}
/**
* @deprecated Since 2.5
*/
@Deprecated
public static JsonSerializer<Object> getStdKeySerializer(JavaType keyType) {
return getStdKeySerializer(null, keyType.getRawClass(), true);
}
public static JsonSerializer<Object> getDefault() {
return DEFAULT_KEY_SERIALIZER;
}
/*
/**********************************************************
/* Standard implementations used
/**********************************************************
*/
public static class Default extends StdSerializer<Object> {
final static int TYPE_DATE = 1;
final static int TYPE_CALENDAR = 2;
final static int TYPE_CLASS = 3;
final static int TYPE_TO_STRING = 4;
protected final int _typeId;
public Default(int typeId, Class<?> type) {
super(type, false);
_typeId = typeId;
}
@Override
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException {
switch (_typeId) {
case TYPE_DATE:
provider.defaultSerializeDateKey
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>valueClass.getName());
}
protected T _deserializeFromEmptyString() throws IOException {
return null;
}
/*
/**********************************************************
/* A general-purpose implementation
/**********************************************************
*/
/**
* "Chameleon" deserializer that works on simple types that are deserialized
* from a simple String.
*
* @since 2.4
*/
public static class Std extends FromStringDeserializer<Object>
{
private static final long serialVersionUID = 1;
public final static int STD_FILE = 1;
public final static int STD_URL = 2;
public final static int STD_URI = 3;
public final static int STD_CLASS = 4;
public final static int STD_JAVA_TYPE = 5;
public final static int STD_CURRENCY = 6;
public final static int STD_PATTERN = 7;
public final static int STD_LOCALE = 8;
public final static int STD_CHARSET = 9;
public final static int STD_TIME_ZONE = 10;
public final static int STD_INET_ADDRESS = 11;
public final static int STD_INET_SOCKET_ADDRESS = 12;
protected final int _kind;
protected Std(Class<?> valueType, int kind) {
super(valueType);
_kind = kind;
}
@Override
protected Object _deserialize(String value, DeserializationContext ctxt) throws IOException
{
switch (_kind) {
case STD_FILE:
return new File(value);
case STD_URL:
return new URL(value);
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
int ix = value.indexOf('_');
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
ix = value.indexOf('_');
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
case STD_INET_SOCKET_ADDRESS:
if
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.exc;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonMappingException;
/**
* Specialized sub-class of {@link JsonMappingException}
* that is used when the underlying problem appears to be that
* of bad formatting of a value to deserialize.
*
* @since 2.1
*/
public class InvalidFormatException extends JsonMappingException
{
private static final long serialVersionUID = 1L; // silly Eclipse, warnings
/**
* Underlying value that could not be deserialized into
* target type, if available.
*/
protected final Object _value;
/**
* Intended target type (type-erased class) that value could not
* be deserialized into, if known.
*/
protected final Class<?> _targetType;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public InvalidFormatException(String msg,
Object value, Class<?> targetType)
{
super(msg);
_value = value;
_targetType = targetType;
}
public InvalidFormatException(String msg, JsonLocation loc,
Object value, Class<?> targetType)
{
super(msg, loc);
_value = value;
_targetType = targetType;
}
public static InvalidFormatException from(JsonParser jp, String msg,
Object value, Class<?> targetType)
{
return new InvalidFormatException(msg, jp.getTokenLocation(),
value, targetType);
}
/*
/**********************************************************
/* Additional accessors
/**********************************************************
*/
/**
* Accessor for checking source value (String, Number usually) that could not
* be deserialized into target type ({@link #getTargetType}).
* Note that value may not be available, depending on who throws the exception
* and when.
*/
public Object getValue() {
return _value;
}
/**
* Accessor for checking target type of value ({@link #getValue} that failed
* to deserialize.
* Note that type may not be available, depending on who throws the exception
* and when.
*/
public Class<?> getTargetType() {
return _targetType;
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.Map;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.PropertyName;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.util.Annotations;
/**
* Wrapper property that is used to handle managed (forward) properties
* Basically just needs to delegate first to actual forward property, and
* then to back property.
*/
public final class ManagedReferenceProperty
extends SettableBeanProperty
{
private static final long serialVersionUID = 1L;
protected final String _referenceName;
/**
* Flag that indicates whether property to handle is a container type
* (array, Collection, Map) or not.
*/
protected final boolean _isContainer;
protected final SettableBeanProperty _managedProperty;
protected final SettableBeanProperty _backProperty;
public ManagedReferenceProperty(SettableBeanProperty forward, String refName,
SettableBeanProperty backward, Annotations contextAnnotations, boolean isContainer)
{
super(forward.getFullName(), forward.getType(), forward.getWrapperName(),
forward.getValueTypeDeserializer(), contextAnnotations,
forward.getMetadata());
_referenceName = refName;
_managedProperty = forward;
_backProperty = backward;
_isContainer = isContainer;
}
protected ManagedReferenceProperty(ManagedReferenceProperty src, JsonDeserializer<?> deser)
{
super(src, deser);
_referenceName = src._referenceName;
_isContainer = src._isContainer;
_managedProperty = src._managedProperty;
_backProperty = src._backProperty;
}
protected ManagedReferenceProperty(ManagedReferenceProperty src, PropertyName newName) {
super(src, newName);
_referenceName = src._referenceName;
_isContainer = src._isContainer;
_managedProperty = src._managedProperty;
_backProperty = src._backProperty;
}
@Override
public ManagedReferenceProperty withName(PropertyName newName) {
return new ManagedReferenceProperty(this, newName);
}
@Override
public ManagedReferenceProperty withValueDeserializer(JsonDeserializer<?> deser) {
return new ManagedReferenceProperty(this, deser);
}
/*
/**********************************************************
/* BeanProperty impl
/**********************************************************
*/
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return _managedProperty.getAnnotation(acls);
}
@Override public AnnotatedMember getMember() { return _managedProperty.getMember(); }
/*
/**********************************************************
/* Overridden methods
/**********************************************************
*/
@Override
public void deserializeAndSet(JsonParser p
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
/**
* Base class for deserializers that handle types that are serialized
* as JSON scalars (non-structured, i.e. non-Object, non-Array, values).
*/
public abstract class StdScalarDeserializer<T> extends StdDeserializer<T>
{
private static final long serialVersionUID = 1L;
protected StdScalarDeserializer(Class<?> vc) { super(vc); }
protected StdScalarDeserializer(JavaType valueType) { super(valueType); }
// since 2.5
protected StdScalarDeserializer(StdScalarDeserializer<?> src) { super(src); }
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException {
return typeDeserializer.deserializeTypedFromScalar(jp, ctxt);
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.deser.ResolvableDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.Converter;
/**
* Deserializer implementation where given Java type is first deserialized
* by a standard Jackson deserializer into a delegate type; and then
* this delegate type is converted using a configured
* {@link Converter} into desired target type.
* Common delegate types to use are {@link java.util.Map}
* and {@link com.fasterxml.jackson.databind.JsonNode}.
*<p>
* Note that although types (delegate, target) may be related, they must not be same; trying
* to do this will result in an exception.
*<p>
* Since 2.5 There is {@link StdNodeBasedDeserializer} that is a simplified version
* for cases where intermediate type is {@link JsonNode}
*
* @param <T> Target type to convert to, from delegate type
*
* @since 2.1
*
* @see StdNodeBasedDeserializer
* @see Converter
*/
public class StdDelegatingDeserializer<T>
extends StdDeserializer<T>
implements ContextualDeserializer, ResolvableDeserializer
{
private static final long serialVersionUID = 1L;
protected final Converter<Object,T> _converter;
/**
* Fully resolved delegate type, with generic information if any available.
*/
protected final JavaType _delegateType;
/**
* Underlying serializer for type <code>T</code>.
*/
protected final JsonDeserializer<Object> _delegateDeserializer;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
@SuppressWarnings("unchecked")
public StdDelegatingDeserializer(Converter<?,T> converter)
{
super(Object.class);
_converter = (Converter<Object,T>)converter;
_delegateType = null;
_delegateDeserializer = null;
}
@SuppressWarnings("unchecked")
public StdDelegatingDeserializer(Converter<Object,T> converter,
JavaType delegateType, JsonDeserializer<?> delegateDeserializer)
{
super(delegateType);
_converter = converter;
_delegateType = delegateType;
_delegateDeserializer = (JsonDeserializer<Object>) delegateDeserializer;
}
/**
* @since 2.5
*/
protected StdDelegatingDeserializer(StdDelegatingDeserializer<T> src)
{
super(src);
_converter = src._converter;
_delegateType = src._delegateType;
_delegateDeserializer = src._delegateDeserializer;
}
/**
* Method used for creating resolved contextual instances. Must be
* overridden when sub-classing.
*/
protected StdDelegatingDeserializer<T> withDelegate(Converter<Object,T> converter,
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.lang.reflect.Method;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.CompactStringObjectMap;
import com.fasterxml.jackson.databind.util.EnumResolver;
/**
* Deserializer class that can deserialize instances of
* specified Enum class from Strings and Integers.
*/
@JacksonStdImpl // was missing until 2.6
public class EnumDeserializer
extends StdScalarDeserializer<Object>
{
private static final long serialVersionUID = 1L;
/**
* @since 2.6
*/
protected final CompactStringObjectMap _enumLookup;
/**
* @since 2.6
*/
protected Object[] _enumsByIndex;
public EnumDeserializer(EnumResolver res)
{
super(res.getEnumClass());
_enumLookup = res.constructLookup();
_enumsByIndex = res.getRawEnums();
}
/**
* Factory method used when Enum instances are to be deserialized
* using a creator (static factory method)
*
* @return Deserializer based on given factory method, if type was suitable;
* null if type can not be used
*/
public static JsonDeserializer<?> deserializerForCreator(DeserializationConfig config,
Class<?> enumClass, AnnotatedMethod factory)
{
// note: caller has verified there's just one arg; but we must verify its type
Class<?> paramClass = factory.getRawParameterType(0);
if (config.canOverrideAccessModifiers()) {
ClassUtil.checkAndFixAccess(factory.getMember());
}
return new FactoryBasedDeserializer(enumClass, factory, paramClass);
}
/*
/**********************************************************
/* Default JsonDeserializer implementation
/**********************************************************
*/
/**
* Because of costs associated with constructing Enum resolvers,
* let's cache instances by default.
*/
@Override
public boolean isCachable() { return true; }
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
JsonToken curr = p.getCurrentToken();
// Usually should just get string value:
if (curr == JsonToken.VALUE_STRING || curr == JsonToken.FIELD_NAME) {
String name = p.getText();
Object result = _enumLookup.find(name);
if (result == null) {
return _deserializeAltString(p, ctxt, name);
}
return result;
}
// But let's consider int acceptable as well (if within ordinal range)
if (curr == JsonToken
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>FOR_ENUMS to allow)");
}
}
protected Class<?> _enumClass() {
return handledType();
}
/*
/**********************************************************
/* Additional helper classes
/**********************************************************
*/
/**
* Deserializer that uses a single-String static factory method
* for locating Enum values by String id.
*/
protected static class FactoryBasedDeserializer
extends StdDeserializer<Object>
implements ContextualDeserializer
{
private static final long serialVersionUID = 1;
// Marker type; null if String expected; otherwise numeric wrapper
protected final Class<?> _inputType;
protected final Method _factory;
protected final JsonDeserializer<?> _deser;
public FactoryBasedDeserializer(Class<?> cls, AnnotatedMethod f,
Class<?> inputType)
{
super(cls);
_factory = f.getAnnotated();
_inputType = inputType;
_deser = null;
}
protected FactoryBasedDeserializer(FactoryBasedDeserializer base,
JsonDeserializer<?> deser) {
super(base._valueClass);
_inputType = base._inputType;
_factory = base._factory;
_deser = deser;
}
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property)
throws JsonMappingException
{
if ((_deser == null) && (_inputType != String.class)) {
return new FactoryBasedDeserializer(this,
ctxt.findContextualValueDeserializer(ctxt.constructType(_inputType), property));
}
return this;
}
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
Object value;
if (_deser != null) {
value = _deser.deserialize(p, ctxt);
} else {
JsonToken curr = p.getCurrentToken();
if (curr == JsonToken.VALUE_STRING || curr == JsonToken.FIELD_NAME) {
value = p.getText();
} else {
value = p.getValueAsString();
}
}
try {
return _factory.invoke(_valueClass, value);
} catch (Exception e) {
Throwable t = ClassUtil.getRootCause(e);
if (t instanceof IOException) {
throw (IOException) t;
}
throw ctxt.instantiationException(_valueClass, t);
}
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException {
if (_deser == null) { // String never has type info
return deserialize(p, ctxt);
}
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
}
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.util;
import java.io.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* Helper for simple bounded maps used for reusing lookup values.
*<p>
* Note that serialization behavior is such that contents are NOT serialized,
* on assumption that all use cases are for caching where persistence
* does not make sense. The only thing serialized is the cache size of Map.
*<p>
* NOTE: since version 2.4.2, this is <b>NOT</b> an LRU-based at all; reason
* being that it is not possible to use JDK components that do LRU _AND_ perform
* well wrt synchronization on multi-core systems. So we choose efficient synchronization
* over potentially more efficient handling of entries.
*<p>
* And yes, there are efficient LRU implementations such as
* <a href="https://code.google.com/p/concurrentlinkedhashmap/">concurrentlinkedhashmap</a>;
* but at this point we really try to keep external deps to minimum. But perhaps
* a shaded variant may be used one day.
*/
public class LRUMap<K,V>
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected final transient int _maxEntries;
protected final transient ConcurrentHashMap<K,V> _map;
public LRUMap(int initialEntries, int maxEntries)
{
// We'll use concurrency level of 4, seems reasonable
_map = new ConcurrentHashMap<K,V>(initialEntries, 0.8f, 4);
_maxEntries = maxEntries;
}
public V put(K key, V value) {
if (_map.size() >= _maxEntries) {
// double-locking, yes, but safe here; trying to avoid "clear storms"
synchronized (this) {
if (_map.size() >= _maxEntries) {
clear();
}
}
}
return _map.put(key, value);
}
/**
* @since 2.5
*/
public V putIfAbsent(K key, V value) {
// not 100% optimal semantically, but better from correctness (never exceeds
// defined maximum) and close enough all in all:
if (_map.size() >= _maxEntries) {
synchronized (this) {
if (_map.size() >= _maxEntries) {
clear();
}
}
}
return _map.putIfAbsent(key, value);
}
// NOTE: key is of type Object only to retain binary backwards-compatibility
public V get(Object key) { return _map.get(key); }
public void clear() { _map.clear(); }
public int size() { return _map.size(); }
/*
/**********************************************************
/* Serializable overrides
/**********************************************************
*/
/**
* Ugly hack, to work through the requirement that _value is indeed final,
*
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import java.util.*;
import com.fasterxml.jackson.databind.JavaType;
/**
* Simple recursive-descent parser for parsing canonical {@link JavaType}
* representations and constructing type instances.
*
* @author tatu
*/
public class TypeParser
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected final TypeFactory _factory;
public TypeParser(TypeFactory f) {
_factory = f;
}
public JavaType parse(String canonical)
throws IllegalArgumentException
{
canonical = canonical.trim();
MyTokenizer tokens = new MyTokenizer(canonical);
JavaType type = parseType(tokens);
// must be end, now
if (tokens.hasMoreTokens()) {
throw _problem(tokens, "Unexpected tokens after complete type");
}
return type;
}
protected JavaType parseType(MyTokenizer tokens)
throws IllegalArgumentException
{
if (!tokens.hasMoreTokens()) {
throw _problem(tokens, "Unexpected end-of-string");
}
Class<?> base = findClass(tokens.nextToken(), tokens);
// either end (ok, non generic type), or generics
if (tokens.hasMoreTokens()) {
String token = tokens.nextToken();
if ("<".equals(token)) {
return _factory._fromParameterizedClass(base, parseTypes(tokens));
}
// can be comma that separates types, or closing '>'
tokens.pushBack(token);
}
return _factory._fromClass(base, null);
}
protected List<JavaType> parseTypes(MyTokenizer tokens)
throws IllegalArgumentException
{
ArrayList<JavaType> types = new ArrayList<JavaType>();
while (tokens.hasMoreTokens()) {
types.add(parseType(tokens));
if (!tokens.hasMoreTokens()) break;
String token = tokens.nextToken();
if (">".equals(token)) return types;
if (!",".equals(token)) {
throw _problem(tokens, "Unexpected token '"+token+"', expected ',' or '>')");
}
}
throw _problem(tokens, "Unexpected end-of-string");
}
protected Class<?> findClass(String className, MyTokenizer tokens)
{
try {
return _factory.findClass(className);
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw _problem(tokens, "Can not locate class '"+className+"', problem: "+e.getMessage());
}
}
protected IllegalArgumentException _problem(MyTokenizer tokens, String msg)
{
return new IllegalArgumentException("Failed to parse type '"+tokens.getAllInput()
+"' (remaining: '"+tokens.getRemainingInput()+"'): "+msg);
}
final static class MyTokenizer
extends StringTokenizer
{
protected final String _input;
protected int _index;
protected String _pushbackToken;
public MyTokenizer(String str) {
super(str, "<,>", true);
_input
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonIntegerFormatVisitor;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonStringFormatVisitor;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
import com.fasterxml.jackson.databind.util.EnumValues;
/**
* Standard serializer used for {@link java.lang.Enum} types.
*<p>
* Based on {@link StdScalarSerializer} since the JSON value is
* scalar (String).
*
* @author tatu
*/
@JacksonStdImpl
public class EnumSerializer
extends StdScalarSerializer<Enum<?>>
implements ContextualSerializer
{
private static final long serialVersionUID = 1L;
/**
* This map contains pre-resolved values (since there are ways
* to customize actual String constants to use) to use as
* serializations.
*/
protected final EnumValues _values;
/**
* Flag that is set if we statically know serialization choice
* between index and textual format (null if it needs to be dynamically
* checked).
*
* @since 2.1
*/
protected final Boolean _serializeAsIndex;
/*
/**********************************************************
/* Construction, initialization
/**********************************************************
*/
/**
* @deprecated Since 2.1
*/
@Deprecated
public EnumSerializer(EnumValues v) {
this(v, null);
}
public EnumSerializer(EnumValues v, Boolean serializeAsIndex)
{
super(v.getEnumClass(), false);
_values = v;
_serializeAsIndex = serializeAsIndex;
}
/**
* Factory method used by {@link com.fasterxml.jackson.databind.ser.BasicSerializerFactory}
* for constructing serializer instance of Enum types.
*
* @since 2.1
*/
@SuppressWarnings("unchecked")
public static EnumSerializer construct(Class<?> enumClass, SerializationConfig config,
BeanDescription beanDesc, JsonFormat.Value format)
{
/* 08-Apr-2015, tatu: As per [databind#749], we can not statically determine
* between name() and toString(), need to construct `EnumValues` with names,
* handle toString() case dynamically (for example)
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import com.fasterxml.jackson.databind.JavaType;
/**
* Type that represents "true" Java Map types.
*/
public final class MapType extends MapLikeType
{
private static final long serialVersionUID = 1L;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
private MapType(Class<?> mapType, JavaType keyT, JavaType valueT,
Object valueHandler, Object typeHandler, boolean asStatic) {
super(mapType, keyT, valueT, valueHandler, typeHandler, asStatic);
}
public static MapType construct(Class<?> rawType, JavaType keyT, JavaType valueT) {
// nominally component types will be just Object.class
return new MapType(rawType, keyT, valueT, null, null, false);
}
@Override
protected JavaType _narrow(Class<?> subclass) {
return new MapType(subclass, _keyType, _valueType,
_valueHandler, _typeHandler, _asStatic);
}
@Override
public JavaType narrowContentsBy(Class<?> contentClass)
{
// Can do a quick check first:
if (contentClass == _valueType.getRawClass()) {
return this;
}
return new MapType(_class, _keyType, _valueType.narrowBy(contentClass),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public JavaType widenContentsBy(Class<?> contentClass)
{
if (contentClass == _valueType.getRawClass()) {
return this;
}
return new MapType(_class, _keyType, _valueType.widenBy(contentClass),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public JavaType narrowKey(Class<?> keySubclass)
{
// Can do a quick check first:
if (keySubclass == _keyType.getRawClass()) {
return this;
}
return new MapType(_class, _keyType.narrowBy(keySubclass), _valueType,
_valueHandler, _typeHandler, _asStatic);
}
@Override
public JavaType widenKey(Class<?> keySubclass)
{
// Can do a quick check first:
if (keySubclass == _keyType.getRawClass()) {
return this;
}
return new MapType(_class, _keyType.widenBy(keySubclass), _valueType,
_valueHandler, _typeHandler, _asStatic);
}
@Override
public MapType withTypeHandler(Object h) {
return new MapType(_class, _keyType, _valueType, _valueHandler, h, _asStatic);
}
@Override
public MapType withContentTypeHandler(Object h)
{
return new MapType(_class, _keyType, _valueType.withTypeHandler(h),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public MapType withValueHandler(Object h)
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS> {
return new MapType(_class, _keyType, _valueType, h, _typeHandler, _asStatic);
}
@Override
public MapType withContentValueHandler(Object h) {
return new MapType(_class, _keyType, _valueType.withValueHandler(h),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public MapType withStaticTyping() {
if (_asStatic) {
return this;
}
return new MapType(_class, _keyType.withStaticTyping(), _valueType.withStaticTyping(),
_valueHandler, _typeHandler, true);
}
/*
/**********************************************************
/* Overridden accessors
/**********************************************************
*/
@Override
public Class<?> getParameterSource() {
return java.util.Map.class;
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
@Override
public MapType withKeyTypeHandler(Object h)
{
return new MapType(_class, _keyType.withTypeHandler(h), _valueType,
_valueHandler, _typeHandler, _asStatic);
}
@Override
public MapType withKeyValueHandler(Object h) {
return new MapType(_class, _keyType.withValueHandler(h), _valueType,
_valueHandler, _typeHandler, _asStatic);
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public String toString()
{
return "[map type; class "+_class.getName()+", "+_keyType+" -> "+_valueType+"]";
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.exc;
import java.util.*;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonMappingException;
/**
* Specialized {@link JsonMappingException} sub-class specifically used
* to indicate problems due to encountering a JSON property that could
* not be mapped to an Object property (via getter, constructor argument
* or field).
*/
public class UnrecognizedPropertyException
extends PropertyBindingException
{
private static final long serialVersionUID = 1L;
public UnrecognizedPropertyException(String msg, JsonLocation loc,
Class<?> referringClass, String propName,
Collection<Object> propertyIds)
{
super(msg, loc, referringClass, propName, propertyIds);
}
/**
* Factory method used for constructing instances of this exception type.
*
* @param jp Underlying parser used for reading input being used for data-binding
* @param fromObjectOrClass Reference to either instance of problematic type (
* if available), or if not, type itself
* @param propertyName Name of unrecognized property
* @param propertyIds (optional, null if not available) Set of properties that
* type would recognize, if completely known: null if set can not be determined.
*/
public static UnrecognizedPropertyException from(JsonParser jp,
Object fromObjectOrClass, String propertyName,
Collection<Object> propertyIds)
{
if (fromObjectOrClass == null) {
throw new IllegalArgumentException();
}
Class<?> ref;
if (fromObjectOrClass instanceof Class<?>) {
ref = (Class<?>) fromObjectOrClass;
} else {
ref = fromObjectOrClass.getClass();
}
String msg = "Unrecognized field \""+propertyName+"\" (class "+ref.getName()+"), not marked as ignorable";
UnrecognizedPropertyException e = new UnrecognizedPropertyException(msg,
jp.getCurrentLocation(), ref, propertyName, propertyIds);
// but let's also ensure path includes this last (missing) segment
e.prependPath(fromObjectOrClass, propertyName);
return e;
}
/**
* @deprecated Since 2.3, use {@link #getPropertyName} instead.
*/
@Deprecated // since 2.3
public String getUnrecognizedPropertyName() {
return getPropertyName();
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser;
import java.util.*;
import java.util.Map.Entry;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdResolver;
import com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey;
import com.fasterxml.jackson.annotation.SimpleObjectIdResolver;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId;
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.util.ClassUtil;
/**
* Complete {@link DeserializationContext} implementation that adds
* extended API for {@link ObjectMapper} (and {@link ObjectReader})
* to call, as well as implements certain parts that base class
* has left abstract.
* The remaining abstract methods ({@link #createInstance}, {@link #with})
* are left so that custom implementations will properly implement them
* to return intended subtype.
*/
public abstract class DefaultDeserializationContext
extends DeserializationContext
implements java.io.Serializable // since 2.1
{
private static final long serialVersionUID = 1L;
protected transient LinkedHashMap<ObjectIdGenerator.IdKey, ReadableObjectId> _objectIds;
private List<ObjectIdResolver> _objectIdResolvers;
/**
* Constructor that will pass specified deserializer factory and
* cache: cache may be null (in which case default implementation
* will be used), factory can not be null
*/
protected DefaultDeserializationContext(DeserializerFactory df, DeserializerCache cache) {
super(df, cache);
}
protected DefaultDeserializationContext(DefaultDeserializationContext src,
DeserializationConfig config, JsonParser jp, InjectableValues values) {
super(src, config, jp, values);
}
protected DefaultDeserializationContext(DefaultDeserializationContext src,
DeserializerFactory factory) {
super(src, factory);
}
/**
* @since 2.4.4
*/
protected DefaultDeserializationContext(DefaultDeserializationContext src) {
super(src);
}
/**
* Method needed to ensure that {@link ObjectMapper#copy} will work
* properly; specifically, that caches are cleared, but settings
* will otherwise remain identical; and that no sharing of state
* occurs.
*
* @since 2.4.4
*/
public DefaultDeserializationContext copy() {
throw new IllegalStateException("DefaultDeserializationContext sub-class not overriding copy()");
}
/*
/**********************************************************
/* Abstract methods impls, Object Id
/**********************************************************
*/
@Override
public ReadableObjectId findObjectId(Object id, ObjectIdGenerator<?> gen, ObjectIdResolver resolverType)
{
/* 02-Apr-2015, tatu: As per [databind#742] should
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>(deserClass)) {
throw new IllegalStateException("AnnotationIntrospector returned Class "+deserClass.getName()
+"; expected Class<KeyDeserializer>");
}
HandlerInstantiator hi = _config.getHandlerInstantiator();
deser = (hi == null) ? null : hi.keyDeserializerInstance(_config, ann, deserClass);
if (deser == null) {
deser = (KeyDeserializer) ClassUtil.createInstance(deserClass,
_config.canOverrideAccessModifiers());
}
}
// First: need to resolve
if (deser instanceof ResolvableDeserializer) {
((ResolvableDeserializer) deser).resolve(this);
}
return deser;
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Fluent factory method used for constructing a blueprint instance
* with different factory
*/
public abstract DefaultDeserializationContext with(DeserializerFactory factory);
/**
* Method called to create actual usable per-deserialization
* context instance.
*/
public abstract DefaultDeserializationContext createInstance(
DeserializationConfig config, JsonParser jp, InjectableValues values);
/*
/**********************************************************
/* And then the concrete implementation class
/**********************************************************
*/
/**
* Actual full concrete implementation
*/
public final static class Impl extends DefaultDeserializationContext
{
private static final long serialVersionUID = 1L;
/**
* Default constructor for a blueprint object, which will use the standard
* {@link DeserializerCache}, given factory.
*/
public Impl(DeserializerFactory df) {
super(df, null);
}
protected Impl(Impl src,
DeserializationConfig config, JsonParser jp, InjectableValues values) {
super(src, config, jp, values);
}
protected Impl(Impl src) { super(src); }
protected Impl(Impl src, DeserializerFactory factory) {
super(src, factory);
}
@Override
public DefaultDeserializationContext copy() {
if (getClass() != Impl.class) {
return super.copy();
}
return new Impl(this);
}
@Override
public DefaultDeserializationContext createInstance(DeserializationConfig config,
JsonParser jp, InjectableValues values) {
return new Impl(this, config, jp, values);
}
@Override
public DefaultDeserializationContext with(DeserializerFactory factory) {
return new Impl(this, factory);
}
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import com.fasterxml.jackson.databind.JavaType;
/**
* Specialized {@link SimpleType} for types that are referential types,
* that is, values that can be dereferenced to another value (or null),
* of different type.
* Referenced type is accessible using {@link #getContentType()}.
*
* @since 2.6
*/
public class ReferenceType extends SimpleType
{
private static final long serialVersionUID = 1L;
protected final JavaType _referencedType;
protected ReferenceType(Class<?> cls, JavaType refType,
Object valueHandler, Object typeHandler, boolean asStatic)
{
super(cls, refType.hashCode(),
valueHandler, typeHandler, asStatic);
_referencedType = refType;
}
public static ReferenceType construct(Class<?> cls, JavaType refType,
Object valueHandler, Object typeHandler)
{
return new ReferenceType(cls, refType, null, null, false);
}
@Override
public ReferenceType withTypeHandler(Object h)
{
if (h == _typeHandler) {
return this;
}
return new ReferenceType(_class, _referencedType, _valueHandler, h, _asStatic);
}
@Override
public ReferenceType withContentTypeHandler(Object h)
{
if (h == _referencedType.<Object>getTypeHandler()) {
return this;
}
return new ReferenceType(_class, _referencedType.withTypeHandler(h),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public ReferenceType withValueHandler(Object h) {
if (h == _valueHandler) {
return this;
}
return new ReferenceType(_class, _referencedType, h, _typeHandler,_asStatic);
}
@Override
public ReferenceType withContentValueHandler(Object h) {
if (h == _referencedType.<Object>getValueHandler()) {
return this;
}
return new ReferenceType(_class, _referencedType.withValueHandler(h),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public ReferenceType withStaticTyping() {
if (_asStatic) {
return this;
}
return new ReferenceType(_class, _referencedType.withStaticTyping(),
_valueHandler, _typeHandler, true);
}
@Override
protected String buildCanonicalName()
{
StringBuilder sb = new StringBuilder();
sb.append(_class.getName());
sb.append('<');
sb.append(_referencedType.toCanonical());
return sb.toString();
}
/*
/**********************************************************
/* Narrow/widen
/**********************************************************
*/
@Override
protected JavaType _narrow(Class<?> subclass)
{
// Should we check that there is a sub-class relationship?
return new ReferenceType(subclass, _referencedType,
_valueHandler, _typeHandler, _asStatic);
}
/*
/**********************************************************
/* Extended
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.util;
import java.util.*;
/**
* Specialized lookup class that implements functionality similar to
* {@link java.util.Map}, but for special case of key always being
* {@link java.lang.String} and using more compact (and memory-access
* friendly) hashing scheme. Assumption is also that keys are typically
* intern()ed.
*<p>
* Generics are not used to avoid bridge methods and since these maps
* are not exposed as part of external API.
*
* @since 2.6
*/
public final class CompactStringObjectMap
implements java.io.Serializable // since 2.6.2
{
private static final long serialVersionUID = 1L;
/**
* Shared instance that can be used when there are no contents to Map.
*/
private final static CompactStringObjectMap EMPTY = new CompactStringObjectMap(1, 0,
new Object[4]);
private final int _hashMask, _spillCount;
private final Object[] _hashArea;
private CompactStringObjectMap(int hashMask, int spillCount, Object[] hashArea)
{
_hashMask = hashMask;
_spillCount = spillCount;
_hashArea = hashArea;
}
public static <T> CompactStringObjectMap construct(Map<String,T> all)
{
if (all.isEmpty()) { // can this happen?
return EMPTY;
}
// First: calculate size of primary hash area
final int size = findSize(all.size());
final int mask = size-1;
// and allocate enough to contain primary/secondary, expand for spillovers as need be
int alloc = (size + (size>>1)) * 2;
Object[] hashArea = new Object[alloc];
int spillCount = 0;
for (Map.Entry<String,T> entry : all.entrySet()) {
String key = entry.getKey();
int slot = key.hashCode() & mask;
int ix = slot+slot;
// primary slot not free?
if (hashArea[ix] != null) {
// secondary?
ix = (size + (slot >> 1)) << 1;
if (hashArea[ix] != null) {
// ok, spill over.
ix = ((size + (size >> 1) ) << 1) + spillCount;
spillCount += 2;
if (ix >= hashArea.length) {
hashArea = Arrays.copyOf(hashArea, hashArea.length + 4);
}
}
}
hashArea[ix] = key;
hashArea[ix+1] = entry.getValue();
}
return new CompactStringObjectMap(mask, spillCount, hashArea);
}
private final static int findSize(int size)
{
if (size <= 5) {
return 8;
}
if (size <= 12) {
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>() { return _objectIdInfo; }
@Override
public List<BeanPropertyDefinition> findProperties() {
return _properties();
}
@Override
public AnnotatedMethod findJsonValueMethod() {
return (_propCollector == null) ? null
: _propCollector.getJsonValueMethod();
}
@Override
public Set<String> getIgnoredPropertyNames() {
Set<String> ign = (_propCollector == null) ? null
: _propCollector.getIgnoredPropertyNames();
if (ign == null) {
return Collections.emptySet();
}
return ign;
}
@Override
public boolean hasKnownClassAnnotations() {
return _classInfo.hasAnnotations();
}
@Override
public Annotations getClassAnnotations() {
return _classInfo.getAnnotations();
}
@Override
public TypeBindings bindingsForBeanType()
{
if (_bindings == null) {
_bindings = new TypeBindings(_config.getTypeFactory(), _type);
}
return _bindings;
}
@Override
public JavaType resolveType(java.lang.reflect.Type jdkType) {
if (jdkType == null) {
return null;
}
return bindingsForBeanType().resolveType(jdkType);
}
@Override
public AnnotatedConstructor findDefaultConstructor() {
return _classInfo.getDefaultConstructor();
}
@Override
public AnnotatedMethod findAnySetter() throws IllegalArgumentException
{
AnnotatedMethod anySetter = (_propCollector == null) ? null
: _propCollector.getAnySetterMethod();
if (anySetter != null) {
/* Also, let's be somewhat strict on how field name is to be
* passed; String, Object make sense, others not
* so much.
*/
/* !!! 18-May-2009, tatu: how about enums? Can add support if
* requested; easy enough for devs to add support within
* method.
*/
Class<?> type = anySetter.getRawParameterType(0);
if (type != String.class && type != Object.class) {
throw new IllegalArgumentException("Invalid 'any-setter' annotation on method "+anySetter.getName()+"(): first argument not of type String or Object, but "+type.getName());
}
}
return anySetter;
}
@Override
public Map<Object, AnnotatedMember> findInjectables() {
if (_propCollector != null) {
return _propCollector.getInjectables();
}
return Collections.emptyMap();
}
@Override
public List<AnnotatedConstructor> getConstructors() {
return _classInfo.getConstructors();
}
@Override
public Object instantiateBean(boolean fixAccess)
{
AnnotatedConstructor ac = _classInfo.getDefaultConstructor();
if (ac == null) {
return null;
}
if (fixAccess) {
ac.fixAccess();
}
try {
return ac.getAnnotated().newInstance();
} catch (Exception e) {
Throwable t = e;
while (t.getCause()
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser;
import java.io.IOException;
import java.lang.annotation.Annotation;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.impl.FailingDeserializer;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import com.fasterxml.jackson.databind.introspect.ObjectIdInfo;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.ViewMatcher;
/**
* Base class for deserializable properties of a bean: contains
* both type and name definitions, and reflection-based set functionality.
* Concrete sub-classes implement details, so that field- and
* setter-backed properties, as well as a few more esoteric variations,
* can be handled.
*/
@SuppressWarnings("serial")
public abstract class SettableBeanProperty
implements BeanProperty,
java.io.Serializable
{
/**
* To avoid nasty NPEs, let's use a placeholder for _valueDeserializer,
* if real deserializer is not (yet) available.
*
* @since 2.2
*/
protected static final JsonDeserializer<Object> MISSING_VALUE_DESERIALIZER = new FailingDeserializer(
"No _valueDeserializer assigned");
/**
* Logical name of the property (often but not always derived
* from the setter method name)
*/
protected final PropertyName _propName;
/**
* Base type for property; may be a supertype of actual value.
*/
protected final JavaType _type;
/**
* @since 2.2
*/
protected final PropertyName _wrapperName;
/**
* Class that contains this property (either class that declares
* the property or one of its subclasses), class that is
* deserialized using deserializer that contains this property.
*/
protected final transient Annotations _contextAnnotations;
/**
* Deserializer used for handling property value.
*<p>
* NOTE: has been immutable since 2.3
*/
protected final JsonDeserializer<Object> _valueDeserializer;
/**
* If value will contain type information (to support
* polymorphic handling), this is the type deserializer
* used to handle type resolution.
*/
protected final TypeDeserializer _valueTypeDeserializer;
/**
* Additional optional property metadata, such as whether
* property is required, and whether there is additional
* human-readable description
*
* @since 2.3
*/
protected final PropertyMetadata _metadata;
/*
/**********************************************************
/* Configuration that is not yet immutable; generally assigned
/* during initialization process but can not be passed to
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
/**
* Deserializer for {@link EnumMap} values.
* <p>
* Note: casting within this class is all messed up -- just could not figure out a way
* to properly deal with recursive definition of "EnumMap<K extends Enum<K>, V>
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public class EnumMapDeserializer
extends ContainerDeserializerBase<EnumMap<?,?>>
implements ContextualDeserializer
{
private static final long serialVersionUID = 1;
protected final JavaType _mapType;
protected final Class<?> _enumClass;
protected KeyDeserializer _keyDeserializer;
protected JsonDeserializer<Object> _valueDeserializer;
/**
* If value instances have polymorphic type information, this
* is the type deserializer that can handle it
*/
protected final TypeDeserializer _valueTypeDeserializer;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public EnumMapDeserializer(JavaType mapType, KeyDeserializer keyDeserializer, JsonDeserializer<?> valueDeser, TypeDeserializer valueTypeDeser)
{
super(mapType);
_mapType = mapType;
_enumClass = mapType.getKeyType().getRawClass();
_keyDeserializer = keyDeserializer;
_valueDeserializer = (JsonDeserializer<Object>) valueDeser;
_valueTypeDeserializer = valueTypeDeser;
}
public EnumMapDeserializer withResolved(KeyDeserializer keyDeserializer, JsonDeserializer<?> valueDeserializer, TypeDeserializer valueTypeDeser)
{
if ((keyDeserializer == _keyDeserializer) && (valueDeserializer == _valueDeserializer) && (valueTypeDeser == _valueTypeDeserializer)) {
return this;
}
return new EnumMapDeserializer(_mapType, keyDeserializer, valueDeserializer, _valueTypeDeserializer);
}
/**
* Method called to finalize setup of this deserializer,
* when it is known for which property deserializer is needed for.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException
{
// note: instead of finding key deserializer, with enums we actually
// work with regular deserializers (less code duplication; but not
// quite as clean as it ought to be)
KeyDeserializer kd = _keyDeserializer;
if (kd == null) {
kd = ctxt.findKeyDeserializer(_mapType.getKeyType(), property);
}
JsonDeserializer<?> vd = _valueDeserializer;
final JavaType vt = _mapType.getContentType();
if (vd == null) {
vd = ctxt.findContextualValueDeserializer(vt, property);
} else { // if directly assigned, probably not yet contextual, so:
vd = ctxt.handle
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
public class AtomicReferenceDeserializer
extends StdDeserializer<AtomicReference<?>>
implements ContextualDeserializer
{
private static final long serialVersionUID = 1L;
/**
* Type of value that we reference
*/
protected final JavaType _referencedType;
protected final TypeDeserializer _valueTypeDeserializer;
protected final JsonDeserializer<?> _valueDeserializer;
/**
* @param referencedType Parameterization of this reference
*/
public AtomicReferenceDeserializer(JavaType referencedType) {
this(referencedType, null, null);
}
public AtomicReferenceDeserializer(JavaType referencedType, TypeDeserializer typeDeser, JsonDeserializer<?> deser)
{
super(AtomicReference.class);
_referencedType = referencedType;
_valueDeserializer = deser;
_valueTypeDeserializer = typeDeser;
}
public AtomicReferenceDeserializer withResolved(TypeDeserializer typeDeser, JsonDeserializer<?> valueDeser) {
return new AtomicReferenceDeserializer(_referencedType, typeDeser, valueDeser);
}
@Override
public AtomicReference<?> getNullValue(DeserializationContext ctxt) {
return new AtomicReference<Object>();
}
@Deprecated // remove in 2.7
@Override
public AtomicReference<?> getNullValue() {
return new AtomicReference<Object>();
}
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException
{
JsonDeserializer<?> deser = _valueDeserializer;
TypeDeserializer typeDeser = _valueTypeDeserializer;
if (deser == null) {
deser = ctxt.findContextualValueDeserializer(_referencedType, property);
}
if (typeDeser != null) {
typeDeser = typeDeser.forProperty(property);
}
if (deser == _valueDeserializer && typeDeser == _valueTypeDeserializer) {
return this;
}
return withResolved(typeDeser, deser);
}
@Override
public AtomicReference<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
/* 06-Nov-2013, tatu: Looks like the only way to make polymorphic deser to work
* correctly is to add support here; problem being that handler is not available
* for nominal type of AtomicReference but only "contained" type...
*/
if (_valueTypeDeserializer != null) {
return new AtomicReference<Object>(_valueDeserializer.deserializeWithType(jp, ctxt, _valueTypeDeserializer));
}
return new AtomicReference<Object>(_valueDeserializer.deserialize(jp, ctxt));
}
@Override
public Object[] deserializeWithType(JsonParser jp, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException {
return (Object[]) typeDeserializer.deserializeTypedFrom
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
import java.util.Collections;
import com.fasterxml.jackson.databind.util.ClassUtil;
/**
* Intermediate base class for annotated entities that are members of
* a class; fields, methods and constructors. This is a superset
* of things that can represent logical properties as it contains
* constructors in addition to fields and methods.
*/
public abstract class AnnotatedMember
extends Annotated
implements java.io.Serializable
{
private static final long serialVersionUID = 1L; // since 2.5
// 19-Dec-2014, tatu: Similarly, assumed NOT to be needed in cases where
// owning object (ObjectMapper or relatives) is being JDK-serialized
/**
* Class that was resolved to produce this member instance; either class that declared
* the member, or one of its subtypes that inherited it.
*
* @since 2.5
*/
protected final transient AnnotatedClass _context;
// Transient since information not needed after construction, so
// no need to persist
protected final transient AnnotationMap _annotations;
/*
@Deprecated // since 2.5
protected AnnotatedMember(AnnotationMap annotations) {
this(null, annotations);
}
*/
protected AnnotatedMember(AnnotatedClass ctxt, AnnotationMap annotations) {
super();
_context = ctxt;
_annotations = annotations;
}
/**
* Copy-constructor.
*
* @since 2.5
*/
protected AnnotatedMember(AnnotatedMember base) {
_context = base._context;
_annotations = base._annotations;
}
/**
* Actual physical class in which this memmber was declared.
* Note that this may be different from what {@link #getContextClass()} returns;
* "owner" may be a sub-type of "declaring class".
*/
public abstract Class<?> getDeclaringClass();
public abstract Member getMember();
/**
* Accessor for {@link AnnotatedClass} that was the type that was resolved
* and that contains this member: this is either the {@link java.lang.Class}
* in which member was declared, or one of its super types. If distinction
* between result type, and actual class in which declaration was found matters,
* you can compare return value to that of {@link #getDeclaringClass()}.
* The main use for this accessor is (usually) to access class annotations.
*<p>
* Also note that owner property is NOT (JDK-)serialized; this should usually not
* matter, but means that while it is accessible during construction of various
* (de)serializers, it may not be available on per-call basis, if (but only if)
* <code>ObjectMapper</code> (etc) has been serialized/deserialized.
*
* @since 2.5
*/
public AnnotatedClass getContextClass() {
return _context
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.jsontype.impl;
import java.util.*;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.SubtypeResolver;
/**
* Standard {@link SubtypeResolver} implementation.
*/
public class StdSubtypeResolver
extends SubtypeResolver
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected LinkedHashSet<NamedType> _registeredSubtypes;
public StdSubtypeResolver() { }
/*
/**********************************************************
/* Subtype registration
/**********************************************************
*/
@Override
public void registerSubtypes(NamedType... types) {
if (_registeredSubtypes == null) {
_registeredSubtypes = new LinkedHashSet<NamedType>();
}
for (NamedType type : types) {
_registeredSubtypes.add(type);
}
}
@Override
public void registerSubtypes(Class<?>... classes) {
NamedType[] types = new NamedType[classes.length];
for (int i = 0, len = classes.length; i < len; ++i) {
types[i] = new NamedType(classes[i]);
}
registerSubtypes(types);
}
/*
/**********************************************************
/* Resolution by class (serialization)
/**********************************************************
*/
@Override
public Collection<NamedType> collectAndResolveSubtypesByClass(MapperConfig<?> config,
AnnotatedMember property, JavaType baseType)
{
final AnnotationIntrospector ai = config.getAnnotationIntrospector();
// for backwards compatibility, must allow null here:
Class<?> rawBase = (baseType == null) ? property.getRawType() : baseType.getRawClass();
HashMap<NamedType, NamedType> collected = new HashMap<NamedType, NamedType>();
// start with registered subtypes (which have precedence)
if (_registeredSubtypes != null) {
for (NamedType subtype : _registeredSubtypes) {
// is it a subtype of root type?
if (rawBase.isAssignableFrom(subtype.getType())) { // yes
AnnotatedClass curr = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), ai, config);
_collectAndResolve(curr, subtype, config, ai, collected);
}
}
}
// then annotated types for property itself
Collection<NamedType> st = ai.findSubtypes(property);
if (st != null) {
for (NamedType nt : st) {
AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(nt.getType(), ai, config);
_collectAndResolve(ac, nt, config, ai, collected);
}
}
NamedType rootType = new NamedType(rawBase, null);
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import java.io.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.CharacterEscapes;
import com.fasterxml.jackson.core.io.SegmentedStringWriter;
import com.fasterxml.jackson.core.io.SerializedString;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.core.util.*;
import com.fasterxml.jackson.databind.cfg.ContextAttributes;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.*;
import com.fasterxml.jackson.databind.ser.impl.TypeWrappedSerializer;
import com.fasterxml.jackson.databind.type.TypeFactory;
/**
* Builder object that can be used for per-serialization configuration of
* serialization parameters, such as JSON View and root type to use.
* (and thus fully thread-safe with no external synchronization);
* new instances are constructed for different configurations.
* Instances are initially constructed by {@link ObjectMapper} and can be
* reused in completely thread-safe manner with no explicit synchronization
*/
public class ObjectWriter
implements Versioned,
java.io.Serializable // since 2.1
{
private static final long serialVersionUID = 1; // since 2.5
/**
* We need to keep track of explicit disabling of pretty printing;
* easiest to do by a token value.
*/
protected final static PrettyPrinter NULL_PRETTY_PRINTER = new MinimalPrettyPrinter();
/*
/**********************************************************
/* Immutable configuration from ObjectMapper
/**********************************************************
*/
/**
* General serialization configuration settings
*/
protected final SerializationConfig _config;
protected final DefaultSerializerProvider _serializerProvider;
protected final SerializerFactory _serializerFactory;
/**
* Factory used for constructing {@link JsonGenerator}s
*/
protected final JsonFactory _generatorFactory;
/*
/**********************************************************
/* Configuration that can be changed via mutant factories
/**********************************************************
*/
/**
* Container for settings that need to be passed to {@link JsonGenerator}
* constructed for serializing values.
*
* @since 2.5
*/
protected final GeneratorSettings _generatorSettings;
/**
* We may pre-fetch serializer if root type
* is known (has been explicitly declared), and if so, reuse it afterwards.
* This allows avoiding further serializer lookups and increases
* performance a bit on cases where readers are reused.
*
* @since 2.5
*/
protected final Prefetch _prefetch;
/*
/**********************************************************
/* Life-cycle, constructors
/**********************************************************
*/
/**
* Constructor used by {@link ObjectMapper} for initial instantiation
*/
protected ObjectWriter(ObjectMapper mapper, SerializationConfig config,
JavaType rootType, PrettyPrinter
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>.
*
* @since 2.5
*/
public final static class GeneratorSettings
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
public final static GeneratorSettings empty = new GeneratorSettings(null, null, null, null);
/**
* To allow for dynamic enabling/disabling of pretty printing,
* pretty printer can be optionally configured for writer
* as well
*/
public final PrettyPrinter prettyPrinter;
/**
* When using data format that uses a schema, schema is passed
* to generator.
*/
public final FormatSchema schema;
/**
* Caller may want to specify character escaping details, either as
* defaults, or on call-by-call basis.
*/
public final CharacterEscapes characterEscapes;
/**
* Caller may want to override so-called "root value separator",
* String added (verbatim, with no quoting or escaping) between
* values in root context. Default value is a single space character,
* but this is often changed to linefeed.
*/
public final SerializableString rootValueSeparator;
public GeneratorSettings(PrettyPrinter pp, FormatSchema sch,
CharacterEscapes esc, SerializableString rootSep) {
prettyPrinter = pp;
schema = sch;
characterEscapes = esc;
rootValueSeparator = rootSep;
}
public GeneratorSettings with(PrettyPrinter pp) {
// since null would mean "don't care", need to use placeholder to indicate "disable"
if (pp == null) {
pp = NULL_PRETTY_PRINTER;
}
return (pp == prettyPrinter) ? this
: new GeneratorSettings(pp, schema, characterEscapes, rootValueSeparator);
}
public GeneratorSettings with(FormatSchema sch) {
return (schema == sch) ? this
: new GeneratorSettings(prettyPrinter, sch, characterEscapes, rootValueSeparator);
}
public GeneratorSettings with(CharacterEscapes esc) {
return (characterEscapes == esc) ? this
: new GeneratorSettings(prettyPrinter, schema, esc, rootValueSeparator);
}
public GeneratorSettings withRootValueSeparator(String sep) {
if (sep == null) {
if (rootValueSeparator == null) {
return this;
}
} else if (sep.equals(rootValueSeparator)) {
return this;
}
return new GeneratorSettings(prettyPrinter, schema, characterEscapes,
(sep == null) ? null : new SerializedString(sep));
}
public GeneratorSettings withRootValueSeparator(SerializableString sep) {
if (sep == null) {
if (rootValueSeparator == null) {
return this;
}
} else {
if (rootValueSeparator != null
&& sep.getValue().equals(rootValueSeparator.getValue())) {
return this;
}
}
return new GeneratorSettings(prettyPrinter, schema, characterEscapes, sep);
}
/**
* @since 2.6
*/
public void initialize(JsonGenerator gen)
{
PrettyPrinter pp = prettyPrinter;
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS> if (prettyPrinter != null) {
if (pp == NULL_PRETTY_PRINTER) {
gen.setPrettyPrinter(null);
} else {
if (pp instanceof Instantiatable<?>) {
pp = (PrettyPrinter) ((Instantiatable<?>) pp).createInstance();
}
gen.setPrettyPrinter(pp);
}
}
if (characterEscapes != null) {
gen.setCharacterEscapes(characterEscapes);
}
if (schema != null) {
gen.setSchema(schema);
}
if (rootValueSeparator != null) {
gen.setRootValueSeparator(rootValueSeparator);
}
}
}
/**
* As a minor optimization, we will make an effort to pre-fetch a serializer,
* or at least relevant <code>TypeSerializer</code>, if given enough
* information.
*
* @since 2.5
*/
public final static class Prefetch
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
public final static Prefetch empty = new Prefetch(null, null, null);
/**
* Specified root serialization type to use; can be same
* as runtime type, but usually one of its super types
* (parent class or interface it implements).
*/
private final JavaType rootType;
/**
* We may pre-fetch serializer if {@link #rootType}
* is known, and if so, reuse it afterwards.
* This allows avoiding further serializer lookups and increases
* performance a bit on cases where readers are reused.
*/
private final JsonSerializer<Object> valueSerializer;
/**
* When dealing with polymorphic types, we can not pre-fetch
* serializer, but can pre-fetch {@link TypeSerializer}.
*/
private final TypeSerializer typeSerializer;
private Prefetch(JavaType rootT,
JsonSerializer<Object> ser, TypeSerializer typeSer)
{
rootType = rootT;
valueSerializer = ser;
typeSerializer = typeSer;
}
public Prefetch forRootType(ObjectWriter parent, JavaType newType) {
// First: if nominal type not defined, or trivial (java.lang.Object),
// not thing much to do
boolean noType = (newType == null) || newType.isJavaLangObject();
if (noType) {
if ((rootType == null) || (valueSerializer == null)) {
return this;
}
return new Prefetch(null, null, typeSerializer);
}
if (newType.equals(rootType)) {
return this;
}
if (parent.isEnabled(SerializationFeature.EAGER_SERIALIZER_FETCH)) {
DefaultSerializerProvider prov = parent._serializerProvider();
// 17-Dec-2014, tatu: Need to be bit careful here; TypeSerializers are NOT cached,
// so although it'd seem like a good idea to look for those first, and avoid
// serializer for polymorphic types, it is actually more efficient to do the
// reverse here
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.ObjectIdResolver;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.impl.*;
import com.fasterxml.jackson.databind.deser.std.StdDelegatingDeserializer;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.exc.IgnoredPropertyException;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.type.ClassKey;
import com.fasterxml.jackson.databind.util.*;
/**
* Base class for <code>BeanDeserializer</code>.
*/
public abstract class BeanDeserializerBase
extends StdDeserializer<Object>
implements ContextualDeserializer, ResolvableDeserializer,
java.io.Serializable // since 2.1
{
private static final long serialVersionUID = 1;
protected final static PropertyName TEMP_PROPERTY_NAME = new PropertyName("#temporary-name");
/*
/**********************************************************
/* Information regarding type being deserialized
/**********************************************************
*/
/**
* Annotations from the bean class: used for accessing
* annotations during resolution
* (see {@link #resolve}) and
* contextualization (see {@link #createContextual})
*<p>
* Transient since annotations only used during construction.
*/
final private transient Annotations _classAnnotations;
/**
* Declared type of the bean this deserializer handles.
*/
final protected JavaType _beanType;
/**
* Requested shape from bean class annotations.
*/
final protected JsonFormat.Shape _serializationShape;
/*
/**********************************************************
/* Configuration for creating value instance
/**********************************************************
*/
/**
* Object that handles details of constructing initial
* bean value (to which bind data to), unless instance
* is passed (via updateValue())
*/
protected final ValueInstantiator _valueInstantiator;
/**
* Deserializer that is used iff delegate-based creator is
* to be used for deserializing from JSON Object.
*/
protected JsonDeserializer<Object> _delegateDeserializer;
/**
* If the bean needs to be instantiated using constructor
* or factory method
* that takes one or more named properties as argument(s),
* this creator is used for instantiation.
* This value gets resolved during general resolution.
*/
protected PropertyBasedCreator _propertyBasedCreator;
/**
* Flag that is set to mark "non-standard" cases; where either
*
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ext;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.Deserializers;
import com.fasterxml.jackson.databind.ser.Serializers;
/**
* Helper class used for isolating details of handling optional+external types
* (javax.xml classes) from standard factories that offer them.
*/
public class OptionalHandlerFactory implements java.io.Serializable
{
private static final long serialVersionUID = 1;
/* 1.6.1+ To make 2 main "optional" handler groups (javax.xml.stream)
* more dynamic, we better only figure out handlers completely dynamically, if and
* when they are needed. To do this we need to assume package prefixes.
*/
private final static String PACKAGE_PREFIX_JAVAX_XML = "javax.xml.";
private final static String SERIALIZERS_FOR_JAVAX_XML = "com.fasterxml.jackson.databind.ext.CoreXMLSerializers";
private final static String DESERIALIZERS_FOR_JAVAX_XML = "com.fasterxml.jackson.databind.ext.CoreXMLDeserializers";
// Plus we also have a single serializer for DOM Node:
private final static String CLASS_NAME_DOM_NODE = "org.w3c.dom.Node";
private final static String CLASS_NAME_DOM_DOCUMENT = "org.w3c.dom.Node";
private final static String SERIALIZER_FOR_DOM_NODE = "com.fasterxml.jackson.databind.ext.DOMSerializer";
private final static String DESERIALIZER_FOR_DOM_DOCUMENT = "com.fasterxml.jackson.databind.ext.DOMDeserializer$DocumentDeserializer";
private final static String DESERIALIZER_FOR_DOM_NODE = "com.fasterxml.jackson.databind.ext.DOMDeserializer$NodeDeserializer";
public final static OptionalHandlerFactory instance = new OptionalHandlerFactory();
protected OptionalHandlerFactory() { }
/*
/**********************************************************
/* Public API
/**********************************************************
*/
public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type,
BeanDescription beanDesc)
{
Class<?> rawType = type.getRawClass();
String className = rawType.getName();
String factoryName;
if (doesImplement(rawType, CLASS_NAME_DOM_NODE)) {
return (JsonSerializer<?>) instantiate(SERIALIZER_FOR_DOM_NODE);
}
if (className.startsWith(PACKAGE_PREFIX_JAVAX_XML) || hasSupertypeStartingWith(rawType, PACKAGE_PREFIX_JAVAX_XML)) {
factoryName = SERIALIZERS_FOR_JAVAX_XML;
} else {
return null;
}
Object ob = instantiate(factoryName);
if (ob == null) { // could warn, if we had logging system (j.u.l?)
return null;
}
return ((Serializers) ob).findSerializer(config, type, beanDesc);
}
public JsonDeserializer<?> findDeserializer(JavaType type
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import com.fasterxml.jackson.databind.JavaType;
/**
* Type that represents Java Collection types (Lists, Sets).
*/
public final class CollectionType
extends CollectionLikeType
{
private static final long serialVersionUID = 1L;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
private CollectionType(Class<?> collT, JavaType elemT,
Object valueHandler, Object typeHandler, boolean asStatic)
{
super(collT, elemT, valueHandler, typeHandler, asStatic);
}
@Override
protected JavaType _narrow(Class<?> subclass) {
return new CollectionType(subclass, _elementType, null, null, _asStatic);
}
@Override
public JavaType narrowContentsBy(Class<?> contentClass)
{
// Can do a quick check first:
if (contentClass == _elementType.getRawClass()) {
return this;
}
return new CollectionType(_class, _elementType.narrowBy(contentClass),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public JavaType widenContentsBy(Class<?> contentClass)
{
// Can do a quick check first:
if (contentClass == _elementType.getRawClass()) {
return this;
}
return new CollectionType(_class, _elementType.widenBy(contentClass),
_valueHandler, _typeHandler, _asStatic);
}
public static CollectionType construct(Class<?> rawType, JavaType elemT)
{
// nominally component types will be just Object.class
return new CollectionType(rawType, elemT, null, null, false);
}
// Since 1.7:
@Override
public CollectionType withTypeHandler(Object h) {
return new CollectionType(_class, _elementType, _valueHandler, h, _asStatic);
}
// Since 1.7:
@Override
public CollectionType withContentTypeHandler(Object h)
{
return new CollectionType(_class, _elementType.withTypeHandler(h),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public CollectionType withValueHandler(Object h) {
return new CollectionType(_class, _elementType, h, _typeHandler, _asStatic);
}
@Override
public CollectionType withContentValueHandler(Object h) {
return new CollectionType(_class, _elementType.withValueHandler(h),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public CollectionType withStaticTyping() {
if (_asStatic) {
return this;
}
return new CollectionType(_class, _elementType.withStaticTyping(),
_valueHandler, _typeHandler, true);
}
/*
/**********************************************************
/* Overridden accessors
/**********************************************************
*/
@Override
public Class<?> getParameterSource() {
return java.util.Collection.class;
}
/*
/**********************************************************
/* Standard methods
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator;
import com.fasterxml.jackson.databind.deser.impl.PropertyValueBuffer;
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.ArrayBuilders;
/**
* Basic serializer that can take JSON "Object" structure and
* construct a {@link java.util.Map} instance, with typed contents.
*<p>
* Note: for untyped content (one indicated by passing Object.class
* as the type), {@link UntypedObjectDeserializer} is used instead.
* It can also construct {@link java.util.Map}s, but not with specific
* POJO types, only other containers and primitives/wrappers.
*/
@JacksonStdImpl
public class MapDeserializer
extends ContainerDeserializerBase<Map<Object,Object>>
implements ContextualDeserializer, ResolvableDeserializer
{
private static final long serialVersionUID = 1L;
// // Configuration: typing, deserializers
protected final JavaType _mapType;
/**
* Key deserializer to use; either passed via constructor
* (when indicated by annotations), or resolved when
* {@link #resolve} is called;
*/
protected final KeyDeserializer _keyDeserializer;
/**
* Flag set to indicate that the key type is
* {@link java.lang.String} (or {@link java.lang.Object}, for
* which String is acceptable), <b>and</b> that the
* default Jackson key deserializer would be used.
* If both are true, can optimize handling.
*/
protected boolean _standardStringKey;
/**
* Value deserializer.
*/
protected final JsonDeserializer<Object> _valueDeserializer;
/**
* If value instances have polymorphic type information, this
* is the type deserializer that can handle it
*/
protected final TypeDeserializer _valueTypeDeserializer;
// // Instance construction settings:
protected final ValueInstantiator _valueInstantiator;
protected final boolean _hasDefaultCreator;
/**
* Deserializer that is used iff delegate-based creator is
* to be used for deserializing from JSON Object.
*/
protected JsonDeserializer<Object> _delegateDeserializer;
/**
* If the Map is to be instantiated using non-default constructor
* or factory method
* that takes one or more named properties as argument(s),
* this creator is used for instantiation.
*/
protected PropertyBasedCreator _propertyBasedCreator;
// // Any properties to ignore if
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonArrayFormatVisitor;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.std.StaticListSerializerBase;
/**
* Efficient implement for serializing {@link List}s that contains Strings and are random-accessible.
* The only complexity is due to possibility that serializer for {@link String}
* may be overridde; because of this, logic is needed to ensure that the default
* serializer is in use to use fastest mode, or if not, to defer to custom
* String serializer.
*/
@JacksonStdImpl
public final class IndexedStringListSerializer
extends StaticListSerializerBase<List<String>>
{
private static final long serialVersionUID = 1L;
public final static IndexedStringListSerializer instance = new IndexedStringListSerializer();
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
protected IndexedStringListSerializer() {
super(List.class);
}
public IndexedStringListSerializer(IndexedStringListSerializer src,
JsonSerializer<?> ser, Boolean unwrapSingle) {
super(src, ser, unwrapSingle);
}
@Override
public JsonSerializer<?> _withResolved(BeanProperty prop,
JsonSerializer<?> ser, Boolean unwrapSingle) {
return new IndexedStringListSerializer(this, ser, unwrapSingle);
}
@Override protected JsonNode contentSchema() { return createSchemaNode("string", true); }
@Override
protected void acceptContentVisitor(JsonArrayFormatVisitor visitor) throws JsonMappingException {
visitor.itemsFormat(JsonFormatTypes.STRING);
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public void serialize(List<String> value, JsonGenerator gen,
SerializerProvider provider) throws IOException
{
final int len = value.size();
if (len == 1) {
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
_serializeUnwrapped(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
if (_serializer == null) {
serializeContents(value, gen, provider, len);
} else {
serializeUsingCustom(value, gen, provider, len);
}
gen.writeEndArray();
}
private final void _serializeUnwrapped(List<String> value, JsonGenerator gen,
SerializerProvider provider) throws IOException
{
if (_serializer == null) {
serializeContents(value, gen, provider, 1);
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.*;
import java.nio.ByteBuffer;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.util.ByteBufferBackedOutputStream;
public class ByteBufferDeserializer extends StdScalarDeserializer<ByteBuffer>
{
private static final long serialVersionUID = 1L;
protected ByteBufferDeserializer() { super(ByteBuffer.class); }
@Override
public ByteBuffer deserialize(JsonParser parser, DeserializationContext cx) throws IOException {
byte[] b = parser.getBinaryValue();
return ByteBuffer.wrap(b);
}
@Override
public ByteBuffer deserialize(JsonParser jp, DeserializationContext ctxt, ByteBuffer intoValue) throws IOException {
// Let's actually read in streaming manner...
OutputStream out = new ByteBufferBackedOutputStream(intoValue);
jp.readBinaryValue(ctxt.getBase64Variant(), out);
out.close();
return intoValue;
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.util;
import java.util.*;
import com.fasterxml.jackson.core.SerializableString;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
/**
* Helper class used for storing String serializations of
* enumerations.
*/
public final class EnumValues
implements java.io.Serializable
{
private static final long serialVersionUID = 1;
private final Class<Enum<?>> _enumClass;
private final Enum<?>[] _values;
private final SerializableString[] _textual;
private transient EnumMap<?,SerializableString> _asMap;
private EnumValues(Class<Enum<?>> enumClass, SerializableString[] textual)
{
_enumClass = enumClass;
_values = enumClass.getEnumConstants();
_textual = textual;
}
/**
* NOTE: do NOT call this if configuration may change, and choice between toString()
* and name() might change dynamically.
*/
public static EnumValues construct(SerializationConfig config, Class<Enum<?>> enumClass) {
if (config.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)) {
return constructFromToString(config, enumClass);
}
return constructFromName(config, enumClass);
}
public static EnumValues constructFromName(MapperConfig<?> config, Class<Enum<?>> enumClass)
{
// Enum types with per-instance sub-classes need special handling
Class<? extends Enum<?>> cls = ClassUtil.findEnumType(enumClass);
Enum<?>[] values = cls.getEnumConstants();
if (values != null) {
SerializableString[] textual = new SerializableString[values.length];
for (Enum<?> en : values) {
String value = config.getAnnotationIntrospector().findEnumValue(en);
textual[en.ordinal()] = config.compileString(value);
}
return new EnumValues(enumClass, textual);
}
throw new IllegalArgumentException("Can not determine enum constants for Class "+enumClass.getName());
}
public static EnumValues constructFromToString(MapperConfig<?> config, Class<Enum<?>> enumClass)
{
Class<? extends Enum<?>> cls = ClassUtil.findEnumType(enumClass);
Enum<?>[] values = cls.getEnumConstants();
if (values != null) {
SerializableString[] textual = new SerializableString[values.length];
for (Enum<?> en : values) {
textual[en.ordinal()] = config.compileString(en.toString());
}
return new EnumValues(enumClass, textual);
}
throw new IllegalArgumentException("Can not determine enum constants for Class "+enumClass.getName());
}
public SerializableString serializedValueFor(Enum<?> key) {
return _textual[key.ordinal()];
}
public Collection<SerializableString> values() {
return Arrays.asList(_textual);
}
/**
* Convenience accessor for getting raw Enum instances.
*
* @since 2.6
*/
public List<
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.annotation.Annotation;
import java.lang.reflect.*;
/**
* Placeholder used by virtual properties as placeholder for
* underlying {@link AnnotatedMember}.
*
* @since 2.5
*/
public class VirtualAnnotatedMember extends AnnotatedMember
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected final Class<?> _declaringClass;
protected final Class<?> _rawType;
protected final String _name;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public VirtualAnnotatedMember(AnnotatedClass contextClass, Class<?> declaringClass,
String name, Class<?> rawType)
{
super(contextClass, /* AnnotationMap*/ null);
_declaringClass = declaringClass;
_rawType = rawType;
_name = name;
}
@Override
public Annotated withAnnotations(AnnotationMap fallback) {
return this;
}
/*
/**********************************************************
/* Annotated impl
/**********************************************************
*/
@Override
public Field getAnnotated() { return null; }
@Override
public int getModifiers() { return 0; }
@Override
public String getName() { return _name; }
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return null;
}
@Override
public Type getGenericType() {
return _rawType;
}
@Override
public Class<?> getRawType() {
return _rawType;
}
/*
/**********************************************************
/* AnnotatedMember impl
/**********************************************************
*/
@Override
public Class<?> getDeclaringClass() { return _declaringClass; }
@Override
public Member getMember() { return null; }
@Override
public void setValue(Object pojo, Object value) throws IllegalArgumentException {
throw new IllegalArgumentException("Can not set virtual property '"+_name+"'");
}
@Override
public Object getValue(Object pojo) throws IllegalArgumentException {
throw new IllegalArgumentException("Can not get virtual property '"+_name+"'");
}
/*
/**********************************************************
/* Extended API, generic
/**********************************************************
*/
public String getFullName() {
return getDeclaringClass().getName() + "#" + getName();
}
public int getAnnotationCount() { return 0; }
@Override
public int hashCode() {
return _name.hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
VirtualAnnotatedMember other = (VirtualAnnotatedMember) o;
return (other._declaringClass == _declaringClass)
&& other._name.equals(_name);
}
@Override
public String toString() {
return "[field "+getFullName()+"]";
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonSerializable;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
public abstract class TypeBase
extends JavaType
implements JsonSerializable
{
private static final long serialVersionUID = -3581199092426900829L;
/**
* Lazily initialized external representation of the type
*/
volatile transient String _canonicalName;
/**
* @deprecated Since 2.2 use method that takes 'asStatic' argument
*/
@Deprecated
protected TypeBase(Class<?> raw, int hash,
Object valueHandler, Object typeHandler)
{
this(raw, hash, valueHandler, typeHandler, false);
}
/**
* Main constructor to use by extending classes.
*/
protected TypeBase(Class<?> raw, int hash,
Object valueHandler, Object typeHandler, boolean asStatic)
{
super(raw, hash, valueHandler, typeHandler, asStatic);
}
@Override
public String toCanonical()
{
String str = _canonicalName;
if (str == null) {
str = buildCanonicalName();
}
return str;
}
protected abstract String buildCanonicalName();
@Override
public abstract StringBuilder getGenericSignature(StringBuilder sb);
@Override
public abstract StringBuilder getErasedSignature(StringBuilder sb);
@Override
@SuppressWarnings("unchecked")
public <T> T getValueHandler() { return (T) _valueHandler; }
@Override
@SuppressWarnings("unchecked")
public <T> T getTypeHandler() { return (T) _typeHandler; }
/*
/**********************************************************
/* JsonSerializableWithType base implementation
/**********************************************************
*/
@Override
public void serializeWithType(JsonGenerator jgen, SerializerProvider provider,
TypeSerializer typeSer)
throws IOException, JsonProcessingException
{
typeSer.writeTypePrefixForScalar(this, jgen);
this.serialize(jgen, provider);
typeSer.writeTypeSuffixForScalar(this, jgen);
}
@Override
public void serialize(JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jgen.writeString(toCanonical());
}
/*
/**********************************************************
/* Methods for sub-classes to use
/**********************************************************
*/
/**
* @param trailingSemicolon Whether to add trailing semicolon for non-primitive
* (reference) types or not
*/
protected static StringBuilder _classSignature(Class<?> cls, StringBuilder sb,
boolean trailingSemicolon)
{
if (cls.isPrimitive()) {
if (cls == Boolean.TYPE) {
sb.append('Z');
} else if (cls == Byte.TYPE)
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.Annotations;
/**
* This concrete sub-class implements property that is set
* using regular "setter" method.
*/
public final class MethodProperty
extends SettableBeanProperty
{
private static final long serialVersionUID = 1;
protected final AnnotatedMethod _annotated;
/**
* Setter method for modifying property value; used for
* "regular" method-accessible properties.
*/
protected final transient Method _setter;
public MethodProperty(BeanPropertyDefinition propDef,
JavaType type, TypeDeserializer typeDeser,
Annotations contextAnnotations, AnnotatedMethod method)
{
super(propDef, type, typeDeser, contextAnnotations);
_annotated = method;
_setter = method.getAnnotated();
}
protected MethodProperty(MethodProperty src, JsonDeserializer<?> deser) {
super(src, deser);
_annotated = src._annotated;
_setter = src._setter;
}
protected MethodProperty(MethodProperty src, PropertyName newName) {
super(src, newName);
_annotated = src._annotated;
_setter = src._setter;
}
/**
* Constructor used for JDK Serialization when reading persisted object
*/
protected MethodProperty(MethodProperty src, Method m) {
super(src);
_annotated = src._annotated;
_setter = m;
}
@Override
public MethodProperty withName(PropertyName newName) {
return new MethodProperty(this, newName);
}
@Override
public MethodProperty withValueDeserializer(JsonDeserializer<?> deser) {
return new MethodProperty(this, deser);
}
/*
/**********************************************************
/* BeanProperty impl
/**********************************************************
*/
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return (_annotated == null) ? null : _annotated.getAnnotation(acls);
}
@Override public AnnotatedMember getMember() { return _annotated; }
/*
/**********************************************************
/* Overridden methods
/**********************************************************
*/
@Override
public void deserializeAndSet(JsonParser jp, DeserializationContext ctxt,
Object instance) throws IOException
{
Object value = deserialize(jp, ctxt);
try {
_setter.invoke(instance, value);
} catch (Exception e) {
_throwAsIOE(e, value);
}
}
@Override
public Object deserializeSetAndReturn(JsonParser jp,
DeserializationContext ctxt, Object instance) throws IOException
{
Object value = deserialize(jp, ctxt);
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.impl.*;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.util.NameTransformer;
import com.fasterxml.jackson.databind.util.TokenBuffer;
/**
* Class that handles deserialization using a separate
* Builder class, which is used for data binding and
* produces actual deserialized value at the end
* of data binding.
*<p>
* Note on implementation: much of code has been copied from
* {@link BeanDeserializer}; there may be opportunities to
* refactor this in future.
*/
public class BuilderBasedDeserializer
extends BeanDeserializerBase
{
private static final long serialVersionUID = 1L;
protected final AnnotatedMethod _buildMethod;
/*
/**********************************************************
/* Life-cycle, construction, initialization
/**********************************************************
*/
/**
* Constructor used by {@link BeanDeserializerBuilder}.
*/
public BuilderBasedDeserializer(BeanDeserializerBuilder builder,
BeanDescription beanDesc,
BeanPropertyMap properties, Map<String, SettableBeanProperty> backRefs,
HashSet<String> ignorableProps, boolean ignoreAllUnknown,
boolean hasViews)
{
super(builder, beanDesc, properties, backRefs,
ignorableProps, ignoreAllUnknown, hasViews);
_buildMethod = builder.getBuildMethod();
// 05-Mar-2012, tatu: Can not really make Object Ids work with builders, not yet anyway
if (_objectIdReader != null) {
throw new IllegalArgumentException("Can not use Object Id with Builder-based deserialization (type "
+beanDesc.getType()+")");
}
}
/**
* Copy-constructor that can be used by sub-classes to allow
* copy-on-write styling copying of settings of an existing instance.
*/
protected BuilderBasedDeserializer(BuilderBasedDeserializer src)
{
this(src, src._ignoreAllUnknown);
}
protected BuilderBasedDeserializer(BuilderBasedDeserializer src, boolean ignoreAllUnknown)
{
super(src, ignoreAllUnknown);
_buildMethod = src._buildMethod;
}
protected BuilderBasedDeserializer(BuilderBasedDeserializer src, NameTransformer unwrapper) {
super(src, unwrapper);
_buildMethod = src._buildMethod;
}
public BuilderBasedDeserializer(BuilderBasedDeserializer src, ObjectIdReader oir) {
super(src, oir);
_buildMethod = src._buildMethod;
}
public BuilderBasedDeserializer(BuilderBasedDeserializer src, HashSet<String> ignorableProps) {
super(src, ignorableProps);
_buildMethod = src._buildMethod;
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper)
{
/* main thing really is to just enforce ignoring of unknown
* properties;
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.PropertyName;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.Annotations;
/**
* This concrete sub-class implements Collection or Map property that is
* indirectly by getting the property value and directly modifying it.
*/
public final class SetterlessProperty
extends SettableBeanProperty
{
private static final long serialVersionUID = 1L;
protected final AnnotatedMethod _annotated;
/**
* Get method for accessing property value used to access property
* (of Collection or Map type) to modify.
*/
protected final Method _getter;
public SetterlessProperty(BeanPropertyDefinition propDef, JavaType type,
TypeDeserializer typeDeser, Annotations contextAnnotations, AnnotatedMethod method) {
super(propDef, type, typeDeser, contextAnnotations);
_annotated = method;
_getter = method.getAnnotated();
}
protected SetterlessProperty(SetterlessProperty src, JsonDeserializer<?> deser) {
super(src, deser);
_annotated = src._annotated;
_getter = src._getter;
}
protected SetterlessProperty(SetterlessProperty src, PropertyName newName) {
super(src, newName);
_annotated = src._annotated;
_getter = src._getter;
}
@Override
public SetterlessProperty withName(PropertyName newName) {
return new SetterlessProperty(this, newName);
}
@Override
public SetterlessProperty withValueDeserializer(JsonDeserializer<?> deser) {
return new SetterlessProperty(this, deser);
}
/*
/**********************************************************
/* BeanProperty impl
/**********************************************************
*/
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return _annotated.getAnnotation(acls);
}
@Override public AnnotatedMember getMember() { return _annotated; }
/*
/**********************************************************
/* Overridden methods
/**********************************************************
*/
@Override
public final void deserializeAndSet(JsonParser jp, DeserializationContext ctxt,
Object instance)
throws IOException, JsonProcessingException
{
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.util.Collection;
import java.util.Map;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.type.SimpleType;
import com.fasterxml.jackson.databind.util.LRUMap;
public class BasicClassIntrospector
extends ClassIntrospector
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/* We keep a small set of pre-constructed descriptions to use for
* common non-structured values, such as Numbers and Strings.
* This is strictly performance optimization to reduce what is
* usually one-time cost, but seems useful for some cases considering
* simplicity.
*
* @since 2.4
*/
protected final static BasicBeanDescription STRING_DESC;
static {
AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(String.class, null, null);
STRING_DESC = BasicBeanDescription.forOtherUse(null, SimpleType.constructUnsafe(String.class), ac);
}
protected final static BasicBeanDescription BOOLEAN_DESC;
static {
AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(Boolean.TYPE, null, null);
BOOLEAN_DESC = BasicBeanDescription.forOtherUse(null, SimpleType.constructUnsafe(Boolean.TYPE), ac);
}
protected final static BasicBeanDescription INT_DESC;
static {
AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(Integer.TYPE, null, null);
INT_DESC = BasicBeanDescription.forOtherUse(null, SimpleType.constructUnsafe(Integer.TYPE), ac);
}
protected final static BasicBeanDescription LONG_DESC;
static {
AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(Long.TYPE, null, null);
LONG_DESC = BasicBeanDescription.forOtherUse(null, SimpleType.constructUnsafe(Long.TYPE), ac);
}
/*
/**********************************************************
/* Life cycle
/**********************************************************
*/
@Deprecated // since 2.5: construct instance directly
public final static BasicClassIntrospector instance = new BasicClassIntrospector();
/**
* Looks like 'forClassAnnotations()' gets called so frequently that we
* should consider caching to avoid some of the lookups.
*
* @since 2.5
*/
protected final LRUMap<JavaType,BasicBeanDescription> _cachedFCA;
public BasicClassIntrospector() {
// a small cache should go a long way here
_cachedFCA = new LRUMap<JavaType,BasicBeanDescription>(16, 64);
}
/*
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.impl.ObjectIdReader;
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
/**
* Deserializer only used for abstract types used as placeholders during polymorphic
* type handling deserialization. If so, there is no real deserializer associated
* with nominal type, just {@link TypeDeserializer}; and any calls that do not
* pass such resolver will result in an error.
*/
public class AbstractDeserializer
extends JsonDeserializer<Object>
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected final JavaType _baseType;
protected final ObjectIdReader _objectIdReader;
protected final Map<String, SettableBeanProperty> _backRefProperties;
// support for "native" types, which require special care:
protected final boolean _acceptString;
protected final boolean _acceptBoolean;
protected final boolean _acceptInt;
protected final boolean _acceptDouble;
public AbstractDeserializer(BeanDeserializerBuilder builder,
BeanDescription beanDesc, Map<String, SettableBeanProperty> backRefProps)
{
_baseType = beanDesc.getType();
_objectIdReader = builder.getObjectIdReader();
_backRefProperties = backRefProps;
Class<?> cls = _baseType.getRawClass();
_acceptString = cls.isAssignableFrom(String.class);
_acceptBoolean = (cls == Boolean.TYPE) || cls.isAssignableFrom(Boolean.class);
_acceptInt = (cls == Integer.TYPE) || cls.isAssignableFrom(Integer.class);
_acceptDouble = (cls == Double.TYPE) || cls.isAssignableFrom(Double.class);
}
protected AbstractDeserializer(BeanDescription beanDesc)
{
_baseType = beanDesc.getType();
_objectIdReader = null;
_backRefProperties = null;
Class<?> cls = _baseType.getRawClass();
_acceptString = cls.isAssignableFrom(String.class);
_acceptBoolean = (cls == Boolean.TYPE) || cls.isAssignableFrom(Boolean.class);
_acceptInt = (cls == Integer.TYPE) || cls.isAssignableFrom(Integer.class);
_acceptDouble = (cls == Double.TYPE) || cls.isAssignableFrom(Double.class);
}
/**
* Factory method used when constructing instances for non-POJO types, like
* {@link java.util.Map}s.
*
* @since 2.3
*/
public static AbstractDeserializer constructForNonPOJO(BeanDescription beanDesc) {
return new AbstractDeserializer(beanDesc);
}
/*
/**********************************************************
/* Public accessors
/**********************************************************
*/
@Override
public Class<?> handledType() {
return _baseType.getRawClass();
}
@Override
public boolean isC
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Helper class that allows using 2 introspectors such that one
* introspector acts as the primary one to use; and second one
* as a fallback used if the primary does not provide conclusive
* or useful result for a method.
*<p>
* An obvious consequence of priority is that it is easy to construct
* longer chains of introspectors by linking multiple pairs.
* Currently most likely combination is that of using the default
* Jackson provider, along with JAXB annotation introspector.
*<p>
* Note: up until 2.0, this class was an inner class of
* {@link AnnotationIntrospector}; moved here for convenience.
*
* @since 2.1
*/
public class AnnotationIntrospectorPair
extends AnnotationIntrospector
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected final AnnotationIntrospector _primary, _secondary;
public AnnotationIntrospectorPair(AnnotationIntrospector p, AnnotationIntrospector s)
{
_primary = p;
_secondary = s;
}
@Override
public Version version() {
return _primary.version();
}
/**
* Helper method for constructing a Pair from two given introspectors (if
* neither is null); or returning non-null introspector if one is null
* (and return just null if both are null)
*/
public static AnnotationIntrospector create(AnnotationIntrospector primary,
AnnotationIntrospector secondary)
{
if (primary == null) {
return secondary;
}
if (secondary == null) {
return primary;
}
return new AnnotationIntrospectorPair(primary, secondary);
}
@Override
public Collection<AnnotationIntrospector> allIntrospectors() {
return allIntrospectors(new ArrayList<AnnotationIntrospector>());
}
@Override
public Collection<AnnotationInt
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import java.util.*;
import com.fasterxml.jackson.databind.JavaType;
/**
* Simple types are defined as anything other than one of recognized
* container types (arrays, Collections, Maps). For our needs we
* need not know anything further, since we have no way of dealing
* with generic types other than Collections and Maps.
*/
public class SimpleType // note: until 2.6 was final
extends TypeBase
{
private static final long serialVersionUID = 1L;
/**
* In case there are resolved type parameters, this field stores reference
* to that type. It must be {@link #getRawClass()} or its supertype.
*
* @since 2.5
*/
protected final Class<?> _typeParametersFor;
/**
* Generic type arguments for this type.
*/
protected final JavaType[] _typeParameters;
/**
* Names of generic type arguments for this type; will
* match values in {@link #_typeParameters}
*/
protected final String[] _typeNames;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
protected SimpleType(Class<?> cls) {
this(cls, null, null, null, null, false, null);
}
/**
* @deprecated Since 2.5 use variant that takes one more argument
*/
@Deprecated
protected SimpleType(Class<?> cls, String[] typeNames, JavaType[] typeParams,
Object valueHandler, Object typeHandler, boolean asStatic)
{
this(cls, typeNames, typeParams, valueHandler, typeHandler, asStatic, null);
}
/**
*
* @param parametersFrom Interface or abstract class implemented by this type,
* and for which type parameters apply. It may be <code>cls</code> itself,
* but more commonly it is one of its supertypes.
*/
protected SimpleType(Class<?> cls,
String[] typeNames, JavaType[] typeParams,
Object valueHandler, Object typeHandler, boolean asStatic,
Class<?> parametersFrom)
{
super(cls, 0, valueHandler, typeHandler, asStatic);
if (typeNames == null || typeNames.length == 0) {
_typeNames = null;
_typeParameters = null;
} else {
_typeNames = typeNames;
_typeParameters = typeParams;
}
_typeParametersFor = parametersFrom;
}
/**
* Pass-through constructor used by {@link ReferenceType}.
*
* @since 2.6
*/
protected SimpleType(Class<?> cls, int extraHash,
Object valueHandler, Object typeHandler, boolean asStatic)
{
super(cls, extraHash, valueHandler, typeHandler, asStatic);
_typeNames = null;
_typeParameters = null;
_typeParametersFor = cls;
}
/**
* Method used by core Jackson classes: NOT to be used by application code.
*<p>
* NOTE:
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import java.util.Collection;
import com.fasterxml.jackson.databind.JavaType;
/**
* Type that represents things that act similar to {@link java.util.Collection};
* but may or may not be instances of that interface.
* This specifically allows framework to check for configuration and annotation
* settings used for Map types, and pass these to custom handlers that may be more
* familiar with actual type.
*/
public class CollectionLikeType extends TypeBase
{
private static final long serialVersionUID = 1L;
/**
* Type of elements in collection
*/
protected final JavaType _elementType;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
protected CollectionLikeType(Class<?> collT, JavaType elemT,
Object valueHandler, Object typeHandler, boolean asStatic)
{
super(collT, elemT.hashCode(), valueHandler, typeHandler, asStatic);
_elementType = elemT;
}
@Override
protected JavaType _narrow(Class<?> subclass) {
return new CollectionLikeType(subclass, _elementType,
_valueHandler, _typeHandler, _asStatic);
}
@Override
public JavaType narrowContentsBy(Class<?> contentClass)
{
// Can do a quick check first:
if (contentClass == _elementType.getRawClass()) {
return this;
}
return new CollectionLikeType(_class, _elementType.narrowBy(contentClass),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public JavaType widenContentsBy(Class<?> contentClass)
{
// Can do a quick check first:
if (contentClass == _elementType.getRawClass()) {
return this;
}
return new CollectionLikeType(_class, _elementType.widenBy(contentClass),
_valueHandler, _typeHandler, _asStatic);
}
public static CollectionLikeType construct(Class<?> rawType, JavaType elemT)
{
// nominally component types will be just Object.class
return new CollectionLikeType(rawType, elemT, null, null, false);
}
@Override
public CollectionLikeType withTypeHandler(Object h)
{
return new CollectionLikeType(_class, _elementType, _valueHandler, h, _asStatic);
}
@Override
public CollectionLikeType withContentTypeHandler(Object h)
{
return new CollectionLikeType(_class, _elementType.withTypeHandler(h),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public CollectionLikeType withValueHandler(Object h) {
return new CollectionLikeType(_class, _elementType, h, _typeHandler, _asStatic);
}
@Override
public CollectionLikeType withContentValueHandler(Object h) {
return new CollectionLikeType(_class, _elementType.withValueHandler(h),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public CollectionLikeType withStaticTyping() {
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import com.fasterxml.jackson.databind.ser.VirtualBeanPropertyWriter;
import com.fasterxml.jackson.databind.util.Annotations;
/**
* {@link VirtualBeanPropertyWriter} implementation used for
* {@link com.fasterxml.jackson.databind.annotation.JsonAppend},
* to serialize properties backed-by dynamically assignable attribute
* values.
*
* @since 2.5
*/
public class AttributePropertyWriter
extends VirtualBeanPropertyWriter
{
private static final long serialVersionUID = 1;
protected final String _attrName;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
protected AttributePropertyWriter(String attrName, BeanPropertyDefinition propDef,
Annotations contextAnnotations, JavaType declaredType) {
this(attrName, propDef, contextAnnotations, declaredType, propDef.findInclusion());
}
protected AttributePropertyWriter(String attrName, BeanPropertyDefinition propDef,
Annotations contextAnnotations, JavaType declaredType,
JsonInclude.Include inclusion)
{
super(propDef, contextAnnotations, declaredType,
/* value serializer */ null, /* type serializer */ null, /* ser type */ null,
inclusion);
_attrName = attrName;
}
public static AttributePropertyWriter construct(String attrName,
BeanPropertyDefinition propDef,
Annotations contextAnnotations,
JavaType declaredType)
{
return new AttributePropertyWriter(attrName, propDef,
contextAnnotations, declaredType);
}
protected AttributePropertyWriter(AttributePropertyWriter base) {
super(base);
_attrName = base._attrName;
}
/**
* Since this method should typically not be called on this sub-type,
* default implementation simply throws an {@link IllegalStateException}.
*/
@Override
public VirtualBeanPropertyWriter withConfig(MapperConfig<?> config,
AnnotatedClass declaringClass, BeanPropertyDefinition propDef, JavaType type) {
throw new IllegalStateException("Should not be called on this type");
}
/*
/**********************************************************
/* Overrides for actual serialization, value access
/**********************************************************
*/
@Override
protected Object value(Object bean, JsonGenerator jgen, SerializerProvider prov) throws Exception {
return prov.getAttribute(_attrName);
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.util.ClassUtil;
/**
* This sub-class is used to handle special case of value being a
* non-static inner class. If so, we will have to use a special
* alternative for default constructor; but otherwise can delegate
* to regular implementation.
*/
public final class InnerClassProperty
extends SettableBeanProperty
{
private static final long serialVersionUID = 1L;
/**
* Actual property that we use after value construction.
*/
protected final SettableBeanProperty _delegate;
/**
* Constructor used when deserializing this property.
* Transient since there is no need to persist; only needed during
* construction of objects.
*/
final protected transient Constructor<?> _creator;
/**
* Serializable version of single-arg constructor we use for value instantiation.
*/
protected AnnotatedConstructor _annotated;
public InnerClassProperty(SettableBeanProperty delegate,
Constructor<?> ctor)
{
super(delegate);
_delegate = delegate;
_creator = ctor;
}
/**
* Constructor used with JDK Serialization; needed to handle transient
* Constructor, wrap/unwrap in/out-of Annotated variant.
*/
protected InnerClassProperty(InnerClassProperty src, AnnotatedConstructor ann)
{
super(src);
_delegate = src._delegate;
_annotated = ann;
_creator = (_annotated == null) ? null : _annotated.getAnnotated();
if (_creator == null) {
throw new IllegalArgumentException("Missing constructor (broken JDK (de)serialization?)");
}
}
protected InnerClassProperty(InnerClassProperty src, JsonDeserializer<?> deser)
{
super(src, deser);
_delegate = src._delegate.withValueDeserializer(deser);
_creator = src._creator;
}
protected InnerClassProperty(InnerClassProperty src, PropertyName newName) {
super(src, newName);
_delegate = src._delegate.withName(newName);
_creator = src._creator;
}
@Override
public InnerClassProperty withName(PropertyName newName) {
return new InnerClassProperty(this, newName);
}
@Override
public InnerClassProperty withValueDeserializer(JsonDeserializer<?> deser) {
return new InnerClassProperty(this, deser);
}
// // // BeanProperty impl
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return _delegate.getAnnotation(acls);
}
@Override public AnnotatedMember getMember() { return _delegate.getMember(); }
/*
/**********************************************************
/* Deserialization methods
/**********************************************************
*/
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
@JacksonStdImpl
public final class StringDeserializer extends StdScalarDeserializer<String>
{
private static final long serialVersionUID = 1L;
/**
* @since 2.2
*/
public final static StringDeserializer instance = new StringDeserializer();
public StringDeserializer() { super(String.class); }
// since 2.6, slightly faster lookups for this very common type
@Override
public boolean isCachable() { return true; }
@Override
public String deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
JsonToken curr = jp.getCurrentToken();
if (curr == JsonToken.VALUE_STRING) {
return jp.getText();
}
// Issue#381
if (curr == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final String parsed = _parseString(jp, ctxt);
if (jp.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'String' value but there was more than a single value in the array");
}
return parsed;
}
// [JACKSON-330]: need to gracefully handle byte[] data, as base64
if (curr == JsonToken.VALUE_EMBEDDED_OBJECT) {
Object ob = jp.getEmbeddedObject();
if (ob == null) {
return null;
}
if (ob instanceof byte[]) {
return Base64Variants.getDefaultVariant().encode((byte[]) ob, false);
}
// otherwise, try conversion using toString()...
return ob.toString();
}
// allow coercions for other scalar types
String text = jp.getValueAsString();
if (text != null) {
return text;
}
throw ctxt.mappingException(_valueClass, curr);
}
// 1.6: since we can never have type info ("natural type"; String, Boolean, Integer, Double):
// (is it an error to even call this version?)
@Override
public String deserializeWithType(JsonParser jp, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException {
return deserialize(jp, ctxt);
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
/**
* Basic serializer that can take JSON "Object" structure and
* construct a {@link java.util.Map} instance, with typed contents.
*<p>
* Note: for untyped content (one indicated by passing Object.class
* as the type), {@link UntypedObjectDeserializer} is used instead.
* It can also construct {@link java.util.Map}s, but not with specific
* POJO types, only other containers and primitives/wrappers.
*/
@JacksonStdImpl
public class MapEntryDeserializer
extends ContainerDeserializerBase<Map.Entry<Object,Object>>
implements ContextualDeserializer
{
private static final long serialVersionUID = 1;
// // Configuration: typing, deserializers
protected final JavaType _type;
/**
* Key deserializer to use; either passed via constructor
* (when indicated by annotations), or resolved when
* {@link #createContextual} is called;
*/
protected final KeyDeserializer _keyDeserializer;
/**
* Value deserializer.
*/
protected final JsonDeserializer<Object> _valueDeserializer;
/**
* If value instances have polymorphic type information, this
* is the type deserializer that can handle it
*/
protected final TypeDeserializer _valueTypeDeserializer;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public MapEntryDeserializer(JavaType type,
KeyDeserializer keyDeser, JsonDeserializer<Object> valueDeser,
TypeDeserializer valueTypeDeser)
{
super(type);
if (type.containedTypeCount() != 2) { // sanity check
throw new IllegalArgumentException("Missing generic type information for "+type);
}
_type = type;
_keyDeserializer = keyDeser;
_valueDeserializer = valueDeser;
_valueTypeDeserializer = valueTypeDeser;
}
/**
* Copy-constructor that can be used by sub-classes to allow
* copy-on-write styling copying of settings of an existing instance.
*/
protected MapEntryDeserializer(MapEntryDeserializer src)
{
super(src._type);
_type = src._type;
_keyDeserializer = src._keyDeserializer;
_valueDeserializer = src._valueDeserializer;
_valueTypeDeserializer = src._valueTypeDeserializer;
}
protected MapEntryDeserializer(MapEntryDeserializer src,
KeyDeserializer keyDeser, JsonDeserializer<Object> valueDeser,
TypeDeserializer valueTypeDeser)
{
super(src._type);
_type = src._type;
_keyDeserializer = keyDeser;
_valueDeserializer = valueDeser;
_valueTypeDeserializer = valueTypeDeser;
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.lang.reflect.*;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.util.ArrayBuilders;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.LRUMap;
/**
* Class used for creating concrete {@link JavaType} instances,
* given various inputs.
*<p>
* Instances of this class are accessible using {@link com.fasterxml.jackson.databind.ObjectMapper}
* as well as many objects it constructs (like
* {@link com.fasterxml.jackson.databind.DeserializationConfig} and
* {@link com.fasterxml.jackson.databind.SerializationConfig})),
* but usually those objects also
* expose convenience methods (<code>constructType</code>).
* So, you can do for example:
*<pre>
* JavaType stringType = mapper.constructType(String.class);
*</pre>
* However, more advanced methods are only exposed by factory so that you
* may need to use:
*<pre>
* JavaType stringCollection = mapper.getTypeFactory().constructCollectionType(List.class, String.class);
*</pre>
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public final class TypeFactory
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
private final static JavaType[] NO_TYPES = new JavaType[0];
/**
* Globally shared singleton. Not accessed directly; non-core
* code should use per-ObjectMapper instance (via configuration objects).
* Core Jackson code uses {@link #defaultInstance} for accessing it.
*/
protected final static TypeFactory instance = new TypeFactory();
/*
/**********************************************************
/* Caching
/**********************************************************
*/
// // // Let's assume that a small set of core primitive/basic types
// // // will not be modified, and can be freely shared to streamline
// // // parts of processing
protected final static SimpleType CORE_TYPE_STRING = new SimpleType(String.class);
protected final static SimpleType CORE_TYPE_BOOL = new SimpleType(Boolean.TYPE);
protected final static SimpleType CORE_TYPE_INT = new SimpleType(Integer.TYPE);
protected final static SimpleType CORE_TYPE_LONG = new SimpleType(Long.TYPE);
/**
* Since type resolution can be expensive (specifically when resolving
* actual generic types), we will use small cache to avoid repetitive
* resolution of core types
*/
protected final LRUMap<ClassKey, JavaType> _typeCache = new LRUMap<ClassKey, JavaType>(16, 100);
/*
* Looks like construction of {@link JavaType} instances can be
* a bottleneck, esp. for root-level Maps
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.databind.type.ClassKey;
/**
* Simple implementation of {@link ClassIntrospector.MixInResolver}
* that just uses a {@link java.util.Map} for containing mapping
* from target to mix-in classes.
*<p>
* Implementation is only thread-safe after initialization (that is,
* when underlying Map is not modified but only read).
*
* @since 2.6
*/
public class SimpleMixInResolver
implements ClassIntrospector.MixInResolver,
java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* External resolver that gets called before looking at any locally defined
* mix-in target classes.
*/
protected final ClassIntrospector.MixInResolver _overrides;
/**
* Simple mix-in targets defined locally.
*/
protected Map<ClassKey,Class<?>> _localMixIns;
public SimpleMixInResolver(ClassIntrospector.MixInResolver overrides) {
_overrides = overrides;
}
protected SimpleMixInResolver(ClassIntrospector.MixInResolver overrides,
Map<ClassKey,Class<?>> mixins) {
_overrides = overrides;
_localMixIns = mixins;
}
/**
* Mutant factory for constructor a new resolver instance with given
* mix-in resolver override.
*/
public SimpleMixInResolver withOverrides(ClassIntrospector.MixInResolver overrides) {
return new SimpleMixInResolver(overrides, _localMixIns);
}
/**
* Mutant factory method that constructs a new instance that has no locally
* defined mix-in/target mappings.
*/
public SimpleMixInResolver withoutLocalDefinitions() {
return new SimpleMixInResolver(_overrides, null);
}
public void setLocalDefinitions(Map<Class<?>, Class<?>> sourceMixins) {
if (sourceMixins == null || sourceMixins.isEmpty()) {
_localMixIns = null;
}
Map<ClassKey,Class<?>> mixIns = new HashMap<ClassKey,Class<?>>(sourceMixins.size());
for (Map.Entry<Class<?>,Class<?>> en : sourceMixins.entrySet()) {
mixIns.put(new ClassKey(en.getKey()), en.getValue());
}
_localMixIns = mixIns;
}
public void addLocalDefinition(Class<?> target, Class<?> mixinSource) {
if (_localMixIns == null) {
_localMixIns = new HashMap<ClassKey,Class<?>>();
}
_localMixIns.put(new ClassKey(target), mixinSource);
}
@Override
public SimpleMixInResolver copy() {
ClassIntrospector.MixInResolver overrides = (_overrides == null)
? null : _overrides.copy();
Map<ClassKey,Class<?>> mixIns = (_localMixIns == null)
? null : new HashMap<ClassKey,
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser;
import java.lang.reflect.Type;
import java.util.*;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.ObjectIdResolver;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.fasterxml.jackson.databind.cfg.DeserializerFactoryConfig;
import com.fasterxml.jackson.databind.deser.impl.*;
import com.fasterxml.jackson.databind.deser.std.ThrowableDeserializer;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.ArrayBuilders;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.SimpleBeanPropertyDefinition;
/**
* Concrete deserializer factory class that adds full Bean deserializer
* construction logic using class introspection.
* Note that factories specifically do not implement any form of caching:
* aside from configuration they are stateless; caching is implemented
* by other components.
*<p>
* Instances of this class are fully immutable as all configuration is
* done by using "fluent factories" (methods that construct new factory
* instances with different configuration, instead of modifying instance).
*/
public class BeanDeserializerFactory
extends BasicDeserializerFactory
implements java.io.Serializable // since 2.1
{
private static final long serialVersionUID = 1;
/**
* Signature of <b>Throwable.initCause</b> method.
*/
private final static Class<?>[] INIT_CAUSE_PARAMS = new Class<?>[] { Throwable.class };
private final static Class<?>[] NO_VIEWS = new Class<?>[0];
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
/**
* Globally shareable thread-safe instance which has no additional custom deserializers
* registered
*/
public final static BeanDeserializerFactory instance = new BeanDeserializerFactory(
new DeserializerFactoryConfig());
public BeanDeserializerFactory(DeserializerFactoryConfig config) {
super(config);
}
/**
* Method used by module registration functionality, to construct a new bean
* deserializer factory
* with different configuration settings.
*/
@Override
public DeserializerFactory withConfig(DeserializerFactoryConfig config)
{
if (_factoryConfig == config) {
return this;
}
/* 22-Nov-2010, tatu: Handling of subtypes is tricky if we do immutable-with-copy-ctor;
* and we pretty much have to here either choose between losing subtype instance
* when registering additional deserializers, or losing deserializers.
* Instead, let's actually just throw an error if this method is called when subtype
* has not properly overridden this method; this to indicate problem as soon as possible.
*/
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonschema.SchemaAware;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.WritableObjectId;
import com.fasterxml.jackson.databind.util.ClassUtil;
/**
* Standard implementation used by {@link ObjectMapper}:
* adds methods only exposed to {@link ObjectMapper},
* as well as constructors.
*<p>
* Note that class is abstract just because it does not
* define {@link #createInstance} method.
*<p>
* Also note that all custom {@link SerializerProvider}
* implementations must sub-class this class: {@link ObjectMapper}
* requires this type, not basic provider type.
*/
public abstract class DefaultSerializerProvider
extends SerializerProvider
implements java.io.Serializable // since 2.1; only because ObjectWriter needs it
{
private static final long serialVersionUID = 1L;
/*
/**********************************************************
/* State, for non-blueprint instances: Object Id handling
/**********************************************************
*/
/**
* Per-serialization map Object Ids that have seen so far, iff
* Object Id handling is enabled.
*/
protected transient Map<Object, WritableObjectId> _seenObjectIds;
protected transient ArrayList<ObjectIdGenerator<?>> _objectIdGenerators;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
protected DefaultSerializerProvider() { super(); }
protected DefaultSerializerProvider(SerializerProvider src,
SerializationConfig config,SerializerFactory f) {
super(src, config, f);
}
protected DefaultSerializerProvider(DefaultSerializerProvider src) {
super(src);
}
/**
* Method needed to ensure that {@link ObjectMapper#copy} will work
* properly; specifically, that caches are cleared, but settings
* will otherwise remain identical; and that no sharing of state
* occurs.
*
* @since 2.5
*/
public DefaultSerializerProvider copy() {
throw new IllegalStateException("DefaultSerializerProvider sub-class not overriding copy()");
}
/*
/**********************************************************
/* Extended API: methods that ObjectMapper will call
/**********************************************************
*/
/**
* Overridable method, used to create a non-blueprint instances from the blueprint.
* This is needed to retain state during serialization.
*/
public abstract DefaultSerializerProvider createInstance(SerializationConfig config,
SerializerFactory jsf);
/**
*
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>),
* defined as final.
*/
public final static class Impl extends DefaultSerializerProvider {
private static final long serialVersionUID = 1L;
public Impl() { super(); }
public Impl(Impl src) { super(src); }
protected Impl(SerializerProvider src, SerializationConfig config,SerializerFactory f) {
super(src, config, f);
}
@Override
public DefaultSerializerProvider copy()
{
if (getClass() != Impl.class) {
return super.copy();
}
return new Impl(this);
}
@Override
public Impl createInstance(SerializationConfig config, SerializerFactory jsf) {
return new Impl(this, config, jsf);
}
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.KeyDeserializers;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.EnumResolver;
/**
* Helper class used to contain simple/well-known key deserializers.
* Following kinds of Objects can be handled currently:
*<ul>
* <li>Primitive wrappers (Boolean, Byte, Char, Short, Integer, Float, Long, Double)</li>
* <li>Enums (usually not needed, since EnumMap doesn't call us)</li>
* <li>{@link java.util.Date}</li>
* <li>{@link java.util.Calendar}</li>
* <li>{@link java.util.UUID}</li>
* <li>{@link java.util.Locale}</li>
* <li>Anything with constructor that takes a single String arg
* (if not explicitly @JsonIgnore'd)</li>
* <li>Anything with {@code static T valueOf(String)} factory method
* (if not explicitly @JsonIgnore'd)</li>
*</ul>
*/
public class StdKeyDeserializers
implements KeyDeserializers, java.io.Serializable
{
private static final long serialVersionUID = 1L;
public static KeyDeserializer constructEnumKeyDeserializer(EnumResolver enumResolver) {
return new StdKeyDeserializer.EnumKD(enumResolver, null);
}
public static KeyDeserializer constructEnumKeyDeserializer(EnumResolver enumResolver,
AnnotatedMethod factory) {
return new StdKeyDeserializer.EnumKD(enumResolver, factory);
}
public static KeyDeserializer constructDelegatingKeyDeserializer(DeserializationConfig config,
JavaType type, JsonDeserializer<?> deser)
{
return new StdKeyDeserializer.DelegatingKD(type.getRawClass(), deser);
}
public static KeyDeserializer findStringBasedKeyDeserializer(DeserializationConfig config,
JavaType type)
{
/* We don't need full deserialization information, just need to
* know creators.
*/
BeanDescription beanDesc = config.introspect(type);
// Ok, so: can we find T(String) constructor?
Constructor<?> ctor = beanDesc.findSingleArgConstructor(String.class);
if (ctor != null) {
if (config.canOverrideAccessModifiers()) {
ClassUtil.checkAndFixAccess(ctor);
}
return new StdKeyDeserializer.StringCtorKeyDeserializer(ctor);
}
/* or if not, "static T valueOf(String)" (or equivalent marked
* with @JsonCreator annotation?)
*/
Method m = beanDesc.findFactoryMethod(String.class);
if (m != null){
if (config.canOverrideAccessModifiers()) {
ClassUtil.checkAndFixAccess(m);
}
return new StdKey
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.reflect.*;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeBindings;
import com.fasterxml.jackson.databind.util.ClassUtil;
public final class AnnotatedMethod
extends AnnotatedWithParams
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
final protected transient Method _method;
// // Simple lazy-caching:
protected Class<?>[] _paramClasses;
/**
* Field that is used to make JDK serialization work with this
* object.
*
* @since 2.1
*/
protected Serialization _serialization;
/*
/*****************************************************
/* Life-cycle
/*****************************************************
*/
public AnnotatedMethod(AnnotatedClass ctxt, Method method,
AnnotationMap classAnn, AnnotationMap[] paramAnnotations)
{
super(ctxt, classAnn, paramAnnotations);
if (method == null) {
throw new IllegalArgumentException("Can not construct AnnotatedMethod with null Method");
}
_method = method;
}
/**
* Method used for JDK serialization support
* @since 2.1
*/
protected AnnotatedMethod(Serialization ser)
{
super(null, null, null);
_method = null;
_serialization = ser;
}
/**
* Method that constructs a new instance with settings (annotations, parameter annotations)
* of this instance, but with different physical {@link Method}.
*/
public AnnotatedMethod withMethod(Method m) {
return new AnnotatedMethod(_context, m, _annotations, _paramAnnotations);
}
@Override
public AnnotatedMethod withAnnotations(AnnotationMap ann) {
return new AnnotatedMethod(_context, _method, ann, _paramAnnotations);
}
/*
/*****************************************************
/* Annotated impl
/*****************************************************
*/
@Override
public Method getAnnotated() { return _method; }
@Override
public int getModifiers() { return _method.getModifiers(); }
@Override
public String getName() { return _method.getName(); }
/**
* For methods, this returns declared return type, which is only
* useful with getters (setters do not return anything; hence "void"
* type is returned here)
*/
@Override
public Type getGenericType() {
return _method.getGenericReturnType();
}
/**
* For methods, this returns declared return type, which is only
* useful with getters (setters do not usually return anything;
* hence "void" type is returned here)
*/
@Override
public Class<?> getRawType() {
return _method.getReturnType();
}
/**
* As per [JACKSON-468], we need to also allow declaration of local
* type bindings; mostly it will allow defining bounds.
*/
@Override
public JavaType getType(TypeBindings bindings) {
return getType(bindings, _method.getTypeParameters());
}
@Override
public final Object call() throws Exception
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS> != Void.class);
}
/*
/********************************************************
/* Other
/********************************************************
*/
@Override
public String toString() {
return "[method "+getFullName()+"]";
}
@Override
public int hashCode() {
return _method.getName().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
return ((AnnotatedMethod) o)._method == _method;
}
/*
/**********************************************************
/* JDK serialization handling
/**********************************************************
*/
Object writeReplace() {
return new AnnotatedMethod(new Serialization(_method));
}
Object readResolve() {
Class<?> clazz = _serialization.clazz;
try {
Method m = clazz.getDeclaredMethod(_serialization.name,
_serialization.args);
// 06-Oct-2012, tatu: Has "lost" its security override, may need to force back
if (!m.isAccessible()) {
ClassUtil.checkAndFixAccess(m);
}
return new AnnotatedMethod(null, m, null, null);
} catch (Exception e) {
throw new IllegalArgumentException("Could not find method '"+_serialization.name
+"' from Class '"+clazz.getName());
}
}
/**
* Helper class that is used as the workaround to persist
* Field references. It basically just stores declaring class
* and field name.
*/
private final static class Serialization
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected Class<?> clazz;
protected String name;
protected Class<?>[] args;
public Serialization(Method setter) {
clazz = setter.getDeclaringClass();
name = setter.getName();
args = setter.getParameterTypes();
}
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
/**
* Standard deserializer for {@link EnumSet}s.
* <p>
* Note: casting within this class is all messed up -- just could not figure out a way
* to properly deal with recursive definition of "EnumSet<K extends Enum<K>, V>
*/
@SuppressWarnings("rawtypes")
public class EnumSetDeserializer
extends StdDeserializer<EnumSet<?>>
implements ContextualDeserializer
{
private static final long serialVersionUID = 1L; // since 2.5
protected final JavaType _enumType;
protected final Class<Enum> _enumClass;
protected JsonDeserializer<Enum<?>> _enumDeserializer;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
@SuppressWarnings("unchecked" )
public EnumSetDeserializer(JavaType enumType, JsonDeserializer<?> deser)
{
super(EnumSet.class);
_enumType = enumType;
_enumClass = (Class<Enum>) enumType.getRawClass();
// sanity check
if (!_enumClass.isEnum()) {
throw new IllegalArgumentException("Type "+enumType+" not Java Enum type");
}
_enumDeserializer = (JsonDeserializer<Enum<?>>) deser;
}
public EnumSetDeserializer withDeserializer(JsonDeserializer<?> deser) {
if (_enumDeserializer == deser) {
return this;
}
return new EnumSetDeserializer(_enumType, deser);
}
/**
* Because of costs associated with constructing Enum resolvers,
* let's cache instances by default.
*/
@Override
public boolean isCachable() {
// One caveat: content deserializer should prevent caching
if (_enumType.getValueHandler() != null) {
return false;
}
return true;
}
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
JsonDeserializer<?> deser = _enumDeserializer;
if (deser == null) {
deser = ctxt.findContextualValueDeserializer(_enumType, property);
} else { // if directly assigned, probably not yet contextual, so:
deser = ctxt.handleSecondaryContextualization(deser, property, _enumType);
}
return withDeserializer(deser);
}
/*
/**********************************************************
/* JsonDeserializer API
/**********************************************************
*/
@SuppressWarnings("unchecked")
@Override
public EnumSet<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// Ok: must point to START_ARRAY (or equivalent)
if (!jp.isExpectedStartArrayToken()) {
throw ctxt.mappingException(EnumSet.class);
}
EnumSet result = constructSet
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.databind.util.RawValue;
/**
* Base class that specifies methods for getting access to
* Node instances (newly constructed, or shared, depending
* on type), as well as basic implementation of the methods.
* Designed to be sub-classed if extended functionality (additions
* to behavior of node types, mostly) is needed.
*/
public class JsonNodeFactory
implements java.io.Serializable // since 2.1
,JsonNodeCreator // since 2.3
{
// with 2.2
private static final long serialVersionUID = 1L;
private final boolean _cfgBigDecimalExact;
private static final JsonNodeFactory decimalsNormalized
= new JsonNodeFactory(false);
private static final JsonNodeFactory decimalsAsIs
= new JsonNodeFactory(true);
/**
* Default singleton instance that construct "standard" node instances:
* given that this class is stateless, a globally shared singleton
* can be used.
*/
public final static JsonNodeFactory instance = decimalsNormalized;
/**
* Main constructor
*
* <p>The only argument to this constructor is a boolean telling whether
* {@link DecimalNode} instances must be built with exact representations of
* {@link BigDecimal} instances.</p>
*
* <p>This has quite an influence since, for instance, a BigDecimal (and,
* therefore, a DecimalNode) constructed from input string {@code "1.0"} and
* another constructed with input string {@code "1.00"} <b>will not</b> be
* equal, since their scale differs (1 in the first case, 2 in the second
* case).</p>
*
* <p>Note that setting the argument to {@code true} does <i>not</i>
* guarantee a strict inequality between JSON representations: input texts
* {@code "0.1"} and {@code "1e-1"}, for instance, yield two equivalent
* BigDecimal instances since they have the same scale (1).</p>
*
* <p>The no-arg constructor (and the default {@link #instance}) calls this
* constructor with {@code false} as an argument.</p>
*
* @param bigDecimalExact see description
*
* @see BigDecimal
*/
public JsonNodeFactory(boolean bigDecimalExact)
{
_cfgBigDecimalExact = bigDecimalExact;
}
/**
* Default constructor
*
* <p>This calls {@link #JsonNodeFactory(boolean)} with {@code false}
* as an argument.</p>
*/
protected JsonNodeFactory()
{
this(false);
}
/**
* Return a factory instance with the desired behavior for BigDecimals
* <p>See {@link #JsonNodeFactory(boolean)} for a full description.</p>
*
* @param bigDecimalExact see description
* @return a factory instance
*/
public static JsonNodeFactory withExactBigDecimals(boolean bigDecimalExact
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
/**
* Serializer used for primitive boolean, as well as java.util.Boolean
* wrapper type.
*<p>
* Since this is one of "native" types, no type information is ever
* included on serialization (unlike for most scalar types as of 1.5)
*/
@JacksonStdImpl
public final class BooleanSerializer
extends NonTypedScalarSerializerBase<Boolean>
{
private static final long serialVersionUID = 1L;
/**
* Whether type serialized is primitive (boolean) or wrapper
* (java.lang.Boolean); if true, former, if false, latter.
*/
protected final boolean _forPrimitive;
public BooleanSerializer(boolean forPrimitive) {
super(Boolean.class);
_forPrimitive = forPrimitive;
}
@Override
public void serialize(Boolean value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeBoolean(value.booleanValue());
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("boolean", !_forPrimitive);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
{
if (visitor != null) {
visitor.expectBooleanFormat(typeHint);
}
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.cfg;
import com.fasterxml.jackson.databind.ser.*;
import com.fasterxml.jackson.databind.util.ArrayBuilders;
import com.fasterxml.jackson.databind.util.ArrayIterator;
/**
* Configuration settings container class for
* {@link SerializerFactory} implementations.
*/
public final class SerializerFactoryConfig
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Constant for empty <code>Serializers</code> array (which by definition
* is stateless and reusable)
*/
protected final static Serializers[] NO_SERIALIZERS = new Serializers[0];
protected final static BeanSerializerModifier[] NO_MODIFIERS = new BeanSerializerModifier[0];
/**
* List of providers for additional serializers, checked before considering default
* basic or bean serialializers.
*/
protected final Serializers[] _additionalSerializers;
/**
* List of providers for additional key serializers, checked before considering default
* key serialializers.
*/
protected final Serializers[] _additionalKeySerializers;
/**
* List of modifiers that can change the way {@link BeanSerializer} instances
* are configured and constructed.
*/
protected final BeanSerializerModifier[] _modifiers;
public SerializerFactoryConfig() {
this(null, null, null);
}
protected SerializerFactoryConfig(Serializers[] allAdditionalSerializers,
Serializers[] allAdditionalKeySerializers,
BeanSerializerModifier[] modifiers)
{
_additionalSerializers = (allAdditionalSerializers == null) ?
NO_SERIALIZERS : allAdditionalSerializers;
_additionalKeySerializers = (allAdditionalKeySerializers == null) ?
NO_SERIALIZERS : allAdditionalKeySerializers;
_modifiers = (modifiers == null) ? NO_MODIFIERS : modifiers;
}
public SerializerFactoryConfig withAdditionalSerializers(Serializers additional)
{
if (additional == null) {
throw new IllegalArgumentException("Can not pass null Serializers");
}
Serializers[] all = ArrayBuilders.insertInListNoDup(_additionalSerializers, additional);
return new SerializerFactoryConfig(all, _additionalKeySerializers, _modifiers);
}
public SerializerFactoryConfig withAdditionalKeySerializers(Serializers additional)
{
if (additional == null) {
throw new IllegalArgumentException("Can not pass null Serializers");
}
Serializers[] all = ArrayBuilders.insertInListNoDup(_additionalKeySerializers, additional);
return new SerializerFactoryConfig(_additionalSerializers, all, _modifiers);
}
public SerializerFactoryConfig withSerializerModifier(BeanSerializerModifier modifier)
{
if (modifier == null) {
throw new IllegalArgumentException("Can not pass null modifier");
}
BeanSerializerModifier[] modifiers = ArrayBuilders.insertInListNoDup(_modifiers, modifier);
return new SerializerFactoryConfig(_additionalSerializers, _additionalKeySerializers, modifiers);
}
public boolean hasSerializers() { return _additionalSerializers.length > 0; }
public boolean hasKeySerial
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
public class AtomicBooleanDeserializer extends StdScalarDeserializer<AtomicBoolean>
{
private static final long serialVersionUID = 1L;
public AtomicBooleanDeserializer() { super(AtomicBoolean.class); }
@Override
public AtomicBoolean deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return new AtomicBoolean(_parseBooleanPrimitive(jp, ctxt));
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.cfg.SerializerFactoryConfig;
import com.fasterxml.jackson.databind.ext.OptionalHandlerFactory;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.impl.*;
import com.fasterxml.jackson.databind.ser.std.*;
import com.fasterxml.jackson.databind.type.*;
import com.fasterxml.jackson.databind.util.*;
/**
* Factory class that can provide serializers for standard JDK classes,
* as well as custom classes that extend standard classes or implement
* one of "well-known" interfaces (such as {@link java.util.Collection}).
*<p>
* Since all the serializers are eagerly instantiated, and there is
* no additional introspection or customizability of these types,
* this factory is essentially stateless.
*/
@SuppressWarnings("serial")
public abstract class BasicSerializerFactory
extends SerializerFactory
implements java.io.Serializable
{
/*
/**********************************************************
/* Configuration, lookup tables/maps
/**********************************************************
*/
/**
* Since these are all JDK classes, we shouldn't have to worry
* about ClassLoader used to load them. Rather, we can just
* use the class name, and keep things simple and efficient.
*/
protected final static HashMap<String, JsonSerializer<?>> _concrete =
new HashMap<String, JsonSerializer<?>>();
/**
* Actually it may not make much sense to eagerly instantiate all
* kinds of serializers: so this Map actually contains class references,
* not instances
*/
protected final static HashMap<String, Class<? extends JsonSerializer<?>>> _concreteLazy =
new HashMap<String, Class<? extends JsonSerializer<?>>>();
static {
/* String and string-like types (note: date types explicitly
* not included -- can use either textual or numeric serialization)
*/
_concrete.put(String.class.getName(), new StringSerializer());
final ToStringSerializer sls = ToStringSerializer.instance;
_concrete.put(StringBuffer.class.getName(), sls);
_concrete.put(StringBuilder.class.getName(), sls);
_concrete.put(Character.class.getName(), sls);
_concrete.put(Character.TYPE.
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>getName(), sls);
// Primitives/wrappers for primitives (primitives needed for Beans)
NumberSerializers.addAll(_concrete);
_concrete.put(Boolean.TYPE.getName(), new BooleanSerializer(true));
_concrete.put(Boolean.class.getName(), new BooleanSerializer(false));
// Other numbers, more complicated
_concrete.put(BigInteger.class.getName(), new NumberSerializer(BigInteger.class));
_concrete.put(BigDecimal.class.getName(),new NumberSerializer(BigDecimal.class));
// Other discrete non-container types:
// First, Date/Time zoo:
_concrete.put(Calendar.class.getName(), CalendarSerializer.instance);
DateSerializer dateSer = DateSerializer.instance;
_concrete.put(java.util.Date.class.getName(), dateSer);
// note: timestamps are very similar to java.util.Date, thus serialized as such
_concrete.put(java.sql.Timestamp.class.getName(), dateSer);
// leave some of less commonly used ones as lazy, no point in proactive construction
_concreteLazy.put(java.sql.Date.class.getName(), SqlDateSerializer.class);
_concreteLazy.put(java.sql.Time.class.getName(), SqlTimeSerializer.class);
// And then other standard non-structured JDK types
for (Map.Entry<Class<?>,Object> en : StdJdkSerializers.all()) {
Object value = en.getValue();
if (value instanceof JsonSerializer<?>) {
_concrete.put(en.getKey().getName(), (JsonSerializer<?>) value);
} else if (value instanceof Class<?>) {
@SuppressWarnings("unchecked")
Class<? extends JsonSerializer<?>> cls = (Class<? extends JsonSerializer<?>>) value;
_concreteLazy.put(en.getKey().getName(), cls);
} else { // should never happen, but:
throw new IllegalStateException("Internal error: unrecognized value of type "+en.getClass().getName());
}
}
// Jackson-specific type(s)
// (Q: can this ever be sub-classed?)
_concreteLazy.put(TokenBuffer.class.getName(), TokenBufferSerializer.class);
}
/*
/**********************************************************
/* Configuration
/**********************************************************
*/
/**
* Configuration settings for this factory; immutable instance (just like this
* factory), new version created via copy-constructor (fluent-style)
*/
protected final SerializerFactoryConfig _factoryConfig;
/*
/**********************************************************
/* Life cycle
/**********************************************************
*/
/**
* We will provide default constructor to allow sub-classing,
* but make it protected so that no non-singleton instances of
* the class will be instantiated.
*/
protected BasicSerializerFactory(SerializerFactoryConfig config) {
_factoryConfig = (config == null) ? new SerializerFactoryConfig() : config;
}
/**
* Method for getting current {@link SerializerFactoryConfig}.
*<p>
* Note that since instances are immutable, you can NOT change settings
* by accessing an instance and calling methods: this
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS> = _concreteLazy.get(clsName);
if (serClass != null) {
try {
return serClass.newInstance();
} catch (Exception e) {
throw new IllegalStateException("Failed to instantiate standard serializer (of type "+serClass.getName()+"): "
+e.getMessage(), e);
}
}
}
return ser;
}
/**
* Method called to see if one of primary per-class annotations
* (or related, like implementing of {@link JsonSerializable})
* determines the serializer to use.
*<p>
* Currently handles things like:
*<ul>
* <li>If type implements {@link JsonSerializable}, use that
* </li>
* <li>If type has {@link com.fasterxml.jackson.annotation.JsonValue} annotation (or equivalent), build serializer
* based on that property
* </li>
*</ul>
*
* @since 2.0
*/
protected final JsonSerializer<?> findSerializerByAnnotations(SerializerProvider prov,
JavaType type, BeanDescription beanDesc)
throws JsonMappingException
{
Class<?> raw = type.getRawClass();
// First: JsonSerializable?
if (JsonSerializable.class.isAssignableFrom(raw)) {
return SerializableSerializer.instance;
}
// Second: @JsonValue for any type
AnnotatedMethod valueMethod = beanDesc.findJsonValueMethod();
if (valueMethod != null) {
Method m = valueMethod.getAnnotated();
if (prov.canOverrideAccessModifiers()) {
ClassUtil.checkAndFixAccess(m);
}
JsonSerializer<Object> ser = findSerializerFromAnnotation(prov, valueMethod);
return new JsonValueSerializer(m, ser);
}
// No well-known annotations...
return null;
}
/**
* Method for checking if we can determine serializer to use based on set of
* known primary types, checking for set of known base types (exact matches
* having been compared against with <code>findSerializerByLookup</code>).
* This does not include "secondary" interfaces, but
* mostly concrete or abstract base classes.
*/
protected final JsonSerializer<?> findSerializerByPrimaryType(SerializerProvider prov,
JavaType type, BeanDescription beanDesc,
boolean staticTyping)
throws JsonMappingException
{
Class<?> raw = type.getRawClass();
// Then check for optional/external serializers [JACKSON-386]
JsonSerializer<?> ser = findOptionalStdSerializer(prov, type, beanDesc, staticTyping);
if (ser != null) {
return ser;
}
if (Calendar.class.isAssignableFrom(raw)) {
return CalendarSerializer.instance;
}
if (java.util.Date.class.isAssignableFrom(raw)) {
return DateSerializer.instance;
}
if (Map.Entry.class.isAssignableFrom(raw)) {
// 28-Apr-2015, tatu: TypeFactory does it all for us already so
JavaType kt = type.containedType(0);
if (kt == null) {
kt = Type
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>Factory.unknownType();
}
JavaType vt = type.containedType(1);
if (vt == null) {
vt = TypeFactory.unknownType();
}
return buildMapEntrySerializer(prov.getConfig(), type, beanDesc, staticTyping, kt, vt);
}
if (ByteBuffer.class.isAssignableFrom(raw)) {
return new ByteBufferSerializer();
}
if (InetAddress.class.isAssignableFrom(raw)) {
return new InetAddressSerializer();
}
if (InetSocketAddress.class.isAssignableFrom(raw)) {
return new InetSocketAddressSerializer();
}
if (TimeZone.class.isAssignableFrom(raw)) {
return new TimeZoneSerializer();
}
if (java.nio.charset.Charset.class.isAssignableFrom(raw)) {
return ToStringSerializer.instance;
}
if (Number.class.isAssignableFrom(raw)) {
// 21-May-2014, tatu: Couple of alternatives actually
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
if (format != null) {
switch (format.getShape()) {
case STRING:
return ToStringSerializer.instance;
case OBJECT: // need to bail out to let it be serialized as POJO
case ARRAY: // or, I guess ARRAY; otherwise no point in speculating
return null;
default:
}
}
return NumberSerializer.instance;
}
if (Enum.class.isAssignableFrom(raw)) {
return buildEnumSerializer(prov.getConfig(), type, beanDesc);
}
return null;
}
/**
* Overridable method called after checking all other types.
*
* @since 2.2
*/
protected JsonSerializer<?> findOptionalStdSerializer(SerializerProvider prov,
JavaType type, BeanDescription beanDesc, boolean staticTyping)
throws JsonMappingException
{
return OptionalHandlerFactory.instance.findSerializer(prov.getConfig(), type, beanDesc);
}
/**
* Reflection-based serialized find method, which checks if
* given class implements one of recognized "add-on" interfaces.
* Add-on here means a role that is usually or can be a secondary
* trait: for example,
* bean classes may implement {@link Iterable}, but their main
* function is usually something else. The reason for
*/
protected final JsonSerializer<?> findSerializerByAddonType(SerializationConfig config,
JavaType javaType, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException
{
Class<?> type = javaType.getRawClass();
if (Iterator.class.isAssignableFrom(type)) {
JavaType[] params = config.getTypeFactory().findTypeParameters(javaType, Iterator.class);
JavaType vt = (params == null || params.length != 1) ?
TypeFactory.unknownType() : params[0];
return buildIteratorSerializer(config, javaType, beanDesc, staticTyping, vt);
}
if (Iterable.class.isAssignableFrom(type)) {
JavaType[] params = config.getTypeFactory().findTypeParameters(javaType, Iterable.class);
JavaType
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
/**
* Simple deserializer that will call configured type deserializer, passing
* in configured data deserializer, and exposing it all as a simple
* deserializer.
* This is necessary when there is no "parent" deserializer which could handle
* details of calling a {@link TypeDeserializer}, most commonly used with
* root values.
*/
public final class TypeWrappedDeserializer
extends JsonDeserializer<Object>
implements java.io.Serializable // since 2.5
{
private static final long serialVersionUID = 1L;
final protected TypeDeserializer _typeDeserializer;
final protected JsonDeserializer<Object> _deserializer;
@SuppressWarnings("unchecked")
public TypeWrappedDeserializer(TypeDeserializer typeDeser, JsonDeserializer<?> deser)
{
super();
_typeDeserializer = typeDeser;
_deserializer = (JsonDeserializer<Object>) deser;
}
@Override
public Class<?> handledType() {
return _deserializer.handledType();
}
@Override
public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
return _deserializer.deserializeWithType(jp, ctxt, _typeDeserializer);
}
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// should never happen? (if it can, could call on that object)
throw new IllegalStateException("Type-wrapped deserializer's deserializeWithType should never get called");
}
@Override
public Object deserialize(JsonParser jp, DeserializationContext ctxt,
Object intoValue) throws IOException
{
/* 01-Mar-2013, tatu: Hmmh. Tough call as to what to do... need
* to delegate, but will this work reliably? Let's just hope so:
*/
return _deserializer.deserialize(jp, ctxt, intoValue);
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import java.text.DateFormat;
import java.util.*;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.core.util.Instantiatable;
import com.fasterxml.jackson.databind.cfg.*;
import com.fasterxml.jackson.databind.introspect.ClassIntrospector;
import com.fasterxml.jackson.databind.introspect.SimpleMixInResolver;
import com.fasterxml.jackson.databind.introspect.VisibilityChecker;
import com.fasterxml.jackson.databind.jsontype.SubtypeResolver;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.SerializerFactory;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.RootNameLookup;
/**
* Object that contains baseline configuration for serialization
* process. An instance is owned by {@link ObjectMapper}, which
* passes an immutable instance for serialization process to
* {@link SerializerProvider} and {@link SerializerFactory}
* (either directly, or through {@link ObjectWriter}.
*<p>
* Note that instances are considered immutable and as such no copies
* should need to be created for sharing; all copying is done with
* "fluent factory" methods.
*/
public final class SerializationConfig
extends MapperConfigBase<SerializationFeature, SerializationConfig>
implements java.io.Serializable // since 2.1
{
// since 2.5
private static final long serialVersionUID = 1;
// since 2.6
protected final static PrettyPrinter DEFAULT_PRETTY_PRINTER = new DefaultPrettyPrinter();
/**
* Set of {@link SerializationFeature}s enabled.
*/
protected final int _serFeatures;
/**
* Which Bean/Map properties are to be included in serialization?
* Default settings is to include all regardless of value; can be
* changed to only include non-null properties, or properties
* with non-default values.
*/
protected JsonInclude.Include _serializationInclusion = null;
/**
* Object used for resolving filter ids to filter instances.
* Non-null if explicitly defined; null by default.
*/
protected final FilterProvider _filterProvider;
/**
* If "default pretty-printing" is enabled, it will create the instance
* from this blueprint object.
*
* @since 2.6
*/
protected final PrettyPrinter _defaultPrettyPrinter;
/**
* States of {@link com.fasterxml.jackson.core.JsonGenerator.Feature}s to enable/disable.
*/
protected final int _generatorFeatures;
/**
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.AnnotatedField;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
/**
* Class that defines how names of JSON properties ("external names")
* are derived from names of POJO methods and fields ("internal names"),
* in cases where they are not
* auto-detected and no explicit annotations exist for naming.
* Methods are passed information about POJO member for which name is needed,
* as well as default name that would be used if no custom strategy was used.
*<p>
* Default implementation returns suggested ("default") name unmodified.
*<p>
* Note that the strategy is guaranteed to be called once per logical property
* (which may be represented by multiple members; such as pair of a getter and
* a setter), but may be called for each: implementations should not count on
* exact number of times, and should work for any member that represent a
* property.
*<p>
* In absence of a registered custom strategy, default Java property naming strategy
* is used, which leaves field names as is, and removes set/get/is prefix
* from methods (as well as lower-cases initial sequence of capitalized
* characters).
*/
@SuppressWarnings("serial")
public abstract class PropertyNamingStrategy
implements java.io.Serializable
{
/**
* See {@link LowerCaseWithUnderscoresStrategy} for details.
*/
public static final PropertyNamingStrategy CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES =
new LowerCaseWithUnderscoresStrategy();
/**
* See {@link PascalCaseStrategy} for details.
*
* @since 2.1
*/
public static final PropertyNamingStrategy PASCAL_CASE_TO_CAMEL_CASE =
new PascalCaseStrategy();
/**
* See {@link LowerCaseStrategy} for details.
*
* @since 2.4
*/
public static final PropertyNamingStrategy LOWER_CASE = new LowerCaseStrategy();
/*
/**********************************************************
/* API
/**********************************************************
*/
/**
* Method called to find external name (name used in JSON) for given logical
* POJO property,
* as defined by given field.
*
* @param config Configuration in used: either <code>SerializationConfig</code>
* or <code>DeserializationConfig</code>, depending on whether method is called
* during serialization or deserialization
* @param field Field used to access property
* @param defaultName Default name that would be used for property in absence of custom strategy
*
* @return Logical name to use for property that the field represents
*/
public String nameForField(MapperConfig<?> config, AnnotatedField field,
String defaultName)
{
return defaultName;
}
/**
* Method called to find external name (name used
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>WithParams creator, CreatorProperty[] injectables) {
addDelegatingCreator(creator, false, injectables);
}
@Deprecated // since 2.5
public void addPropertyCreator(AnnotatedWithParams creator, CreatorProperty[] properties) {
addPropertyCreator(creator, false, properties);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
/**
* @since 2.1
*/
public boolean hasDefaultCreator() {
return _creators[C_DEFAULT] != null;
}
/**
* @since 2.6
*/
public boolean hasDelegatingCreator() {
return _creators[C_DELEGATE] != null;
}
/**
* @since 2.6
*/
public boolean hasPropertyBasedCreator() {
return _creators[C_PROPS] != null;
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
private <T extends AnnotatedMember> T _fixAccess(T member)
{
if (member != null && _canFixAccess) {
ClassUtil.checkAndFixAccess((Member) member.getAnnotated());
}
return member;
}
protected void verifyNonDup(AnnotatedWithParams newOne, int typeIndex, boolean explicit)
{
final int mask = (1 << typeIndex);
_hasNonDefaultCreator = true;
AnnotatedWithParams oldOne = _creators[typeIndex];
// already had an explicitly marked one?
if (oldOne != null) {
boolean verify;
if ((_explicitCreators & mask) != 0) { // already had explicitly annotated, leave as-is
// but skip, if new one not annotated
if (!explicit) {
return;
}
// both explicit: verify
verify = true;
} else {
// otherwise only verify if neither explicitly annotated.
verify = !explicit;
}
// one more thing: ok to override in sub-class
if (verify && (oldOne.getClass() == newOne.getClass())) {
// [databind#667]: avoid one particular class of bogus problems
Class<?> oldType = oldOne.getRawParameterType(0);
Class<?> newType = newOne.getRawParameterType(0);
if (oldType == newType) {
throw new IllegalArgumentException("Conflicting "+TYPE_DESCS[typeIndex]
+" creators: already had explicitly marked "+oldOne+", encountered "+newOne);
}
// otherwise, which one to choose?
if (newType.isAssignableFrom(oldType)) {
// new type more generic, use old
return;
}
// new type more specific, use it
}
}
if (explicit) {
_explicitCreators |= mask;
}
_creators[typeIndex] = _fixAccess(newOne);
}
/*
/**********************************************************
/* Helper class(es)
/**********************************************************
*/
protected final static class Vanilla
extends ValueInstantiator
implements java.io.Serializable
{
private static final long serialVersionUID = 1L
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import com.fasterxml.jackson.core.SerializableString;
import com.fasterxml.jackson.core.io.SerializedString;
import com.fasterxml.jackson.core.util.InternCache;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
/**
* Simple value class used for containing names of properties as defined
* by annotations (and possibly other configuration sources).
*
* @since 2.1
*/
public class PropertyName
implements java.io.Serializable
{
private static final long serialVersionUID = 1L; // 2.5
private final static String _USE_DEFAULT = "";
private final static String _NO_NAME = "";
/**
* Special placeholder value that indicates that name to use should be
* based on the standard heuristics. This can be different from returning
* null, as null means "no information available, whereas this value
* indicates explicit defaulting.
*/
public final static PropertyName USE_DEFAULT = new PropertyName(_USE_DEFAULT, null);
/**
* Special placeholder value that indicates that there is no name associated.
* Exact semantics to use (if any) depend on actual annotation in use, but
* commonly this value disables behavior for which name would be needed.
*/
public final static PropertyName NO_NAME = new PropertyName(new String(_NO_NAME), null);
/**
* Basic name of the property.
*/
protected final String _simpleName;
/**
* Additional namespace, for formats that have such concept (JSON
* does not, XML does, for example).
*/
protected final String _namespace;
/**
* Lazily-constructed efficient representation of the simple name.
*<p>
* NOTE: not defined as volatile to avoid performance problem with
* concurrent access in multi-core environments; due to statelessness
* of {@link SerializedString} at most leads to multiple instantiations.
*
* @since 2.4
*/
protected SerializableString _encodedSimple;
public PropertyName(String simpleName) {
this(simpleName, null);
}
public PropertyName(String simpleName, String namespace)
{
_simpleName = (simpleName == null) ? "" : simpleName;
_namespace = namespace;
}
// To support JDK serialization, recovery of Singleton instance
protected Object readResolve() {
if (_simpleName == null || _USE_DEFAULT.equals(_simpleName)) {
return USE_DEFAULT;
}
if (_simpleName.equals(_NO_NAME) && _namespace == null) {
return NO_NAME;
}
return this;
}
/**
* @since 2.6
*/
public static PropertyName construct(String simpleName)
{
if (simpleName == null || simpleName.length() == 0) {
return USE_DEFAULT;
}
return new PropertyName(InternCache.instance.intern(simpleName), null);
}
public static PropertyName construct(String simpleName, String ns)
{
if
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.std.StdDelegatingDeserializer;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.type.*;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.Converter;
/**
* Class that defines caching layer between callers (like
* {@link ObjectMapper},
* {@link com.fasterxml.jackson.databind.DeserializationContext})
* and classes that construct deserializers
* ({@link com.fasterxml.jackson.databind.deser.DeserializerFactory}).
*/
public final class DeserializerCache
implements java.io.Serializable // since 2.1 -- needs to be careful tho
{
private static final long serialVersionUID = 1L;
/*
/**********************************************************
/* Caching
/**********************************************************
*/
/**
* We will also cache some dynamically constructed deserializers;
* specifically, ones that are expensive to construct.
* This currently means bean and Enum deserializers; starting with
* 2.5, container deserializers will also be cached.
*<p>
* Given that we don't expect much concurrency for additions
* (should very quickly converge to zero after startup), let's
* define a relatively low concurrency setting.
*/
final protected ConcurrentHashMap<JavaType, JsonDeserializer<Object>> _cachedDeserializers
= new ConcurrentHashMap<JavaType, JsonDeserializer<Object>>(64, 0.75f, 4);
/**
* During deserializer construction process we may need to keep track of partially
* completed deserializers, to resolve cyclic dependencies. This is the
* map used for storing deserializers before they are fully complete.
*/
final protected HashMap<JavaType, JsonDeserializer<Object>> _incompleteDeserializers
= new HashMap<JavaType, JsonDeserializer<Object>>(8);
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public DeserializerCache() { }
/*
/**********************************************************
/* JDK serialization handling
/**********************************************************
*/
Object writeReplace() {
// instead of making this transient, just clear it:
_incompleteDeserializers.clear();
// TODO: clear out "cheap" cached deserializers?
return this;
}
/*
/**********************************************************
/* Access to caching aspects
/**********************************************************
*/
/**
* Method that can be used to determine how many deserializers this
* provider is caching currently
* (if it does caching: default implementation does)
* Exact count depends on what kind of deserializers get cached;
* default implementation caches only dynamically constructed deserializers,
* but not eagerly constructed standard deserializers (which is different
* from how serializer provider works).
*<p>
* The main use case for this
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
/**
* Simple container class used for storing "additional" metadata about
* properties. Carved out to reduce number of distinct properties that
* actual property implementations and placeholders need to store;
* since instances are immutable, they can be freely shared.
*
* @since 2.3
*/
public class PropertyMetadata
implements java.io.Serializable
{
private static final long serialVersionUID = -1;
public final static PropertyMetadata STD_REQUIRED = new PropertyMetadata(Boolean.TRUE, null, null, null);
public final static PropertyMetadata STD_OPTIONAL = new PropertyMetadata(Boolean.FALSE, null, null, null);
public final static PropertyMetadata STD_REQUIRED_OR_OPTIONAL = new PropertyMetadata(null, null, null, null);
/**
* Three states: required, not required and unknown; unknown represented
* as null.
*/
protected final Boolean _required;
/**
* Optional human-readable description associated with the property.
*/
protected final String _description;
/**
* Optional index of the property within containing Object.
*
* @since 2.4
*/
protected final Integer _index;
/**
* Optional default value, as String, for property; not used cor
* any functionality by core databind, offered as metadata for
* extensions.
*/
protected final String _defaultValue;
/*
/**********************************************************
/* Construction, configuration
/**********************************************************
*/
@Deprecated // since 2.4
protected PropertyMetadata(Boolean req, String desc) { this(req, desc, null, null); }
/**
* @since 2.5
*/
protected PropertyMetadata(Boolean req, String desc, Integer index, String def)
{
_required = req;
_description = desc;
_index = index;
_defaultValue = (def == null || def.isEmpty()) ? null : def;
}
/**
* @since 2.4 Use variant that takes more arguments.
*/
@Deprecated
public static PropertyMetadata construct(boolean req, String desc) {
return construct(req, desc, null, null);
}
public static PropertyMetadata construct(boolean req, String desc, Integer index,
String defaultValue) {
if (desc != null || index != null || defaultValue != null) {
return new PropertyMetadata(req, desc, index, defaultValue);
}
return req ? STD_REQUIRED : STD_OPTIONAL;
}
/**
* Minor optimization: let's canonicalize back to placeholders in cases
* where there is no real data to consider
*/
protected Object readResolve()
{
if (_description == null && _index == null && _defaultValue == null) {
if (_required == null) {
return STD_REQUIRED_OR_OPTIONAL;
}
return _required.booleanValue() ? STD_REQUIRED : STD_OPTIONAL;
}
return this;
}
public PropertyMetadata withDescription(String desc) {
return new PropertyMetadata(_required, desc, _index, _defaultValue);
}
public PropertyMetadata withDefaultValue(String
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import com.fasterxml.jackson.databind.util.ClassUtil;
/**
* Object that represents non-static (and usually non-transient/volatile)
* fields of a class.
*/
public final class AnnotatedField
extends AnnotatedMember
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Actual {@link Field} used for access.
*<p>
* Transient since it can not be persisted directly using
* JDK serialization
*/
protected final transient Field _field;
/**
* Temporary field required for JDK serialization support
*/
protected Serialization _serialization;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public AnnotatedField(AnnotatedClass contextClass, Field field, AnnotationMap annMap)
{
super(contextClass, annMap);
_field = field;
}
@Override
public AnnotatedField withAnnotations(AnnotationMap ann) {
return new AnnotatedField(_context, _field, ann);
}
/**
* Method used for JDK serialization support
*/
protected AnnotatedField(Serialization ser)
{
super(null, null);
_field = null;
_serialization = ser;
}
/*
/**********************************************************
/* Annotated impl
/**********************************************************
*/
@Override
public Field getAnnotated() { return _field; }
@Override
public int getModifiers() { return _field.getModifiers(); }
@Override
public String getName() { return _field.getName(); }
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return (_annotations == null) ? null : _annotations.get(acls);
}
@Override
public Type getGenericType() {
return _field.getGenericType();
}
@Override
public Class<?> getRawType() {
return _field.getType();
}
/*
/**********************************************************
/* AnnotatedMember impl
/**********************************************************
*/
@Override
public Class<?> getDeclaringClass() { return _field.getDeclaringClass(); }
@Override
public Member getMember() { return _field; }
@Override
public void setValue(Object pojo, Object value) throws IllegalArgumentException
{
try {
_field.set(pojo, value);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Failed to setValue() for field "
+getFullName()+": "+e.getMessage(), e);
}
}
@Override
public Object getValue(Object pojo) throws IllegalArgumentException
{
try {
return _field.get(pojo);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Failed to getValue() for field "
+getFullName()+": "+e.getMessage(), e);
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>
/*
/**********************************************************
/* Extended API, generic
/**********************************************************
*/
public String getFullName() {
return getDeclaringClass().getName() + "#" + getName();
}
public int getAnnotationCount() { return _annotations.size(); }
/**
* @since 2.6
*/
public boolean isTransient() { return Modifier.isTransient(getModifiers()); }
@Override
public int hashCode() {
return _field.getName().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
return ((AnnotatedField) o)._field == _field;
}
@Override
public String toString() {
return "[field "+getFullName()+"]";
}
/*
/**********************************************************
/* JDK serialization handling
/**********************************************************
*/
Object writeReplace() {
return new AnnotatedField(new Serialization(_field));
}
Object readResolve() {
Class<?> clazz = _serialization.clazz;
try {
Field f = clazz.getDeclaredField(_serialization.name);
// 06-Oct-2012, tatu: Has "lost" its security override, may need to force back
if (!f.isAccessible()) {
ClassUtil.checkAndFixAccess(f);
}
return new AnnotatedField(null, f, null);
} catch (Exception e) {
throw new IllegalArgumentException("Could not find method '"+_serialization.name
+"' from Class '"+clazz.getName());
}
}
/**
* Helper class that is used as the workaround to persist
* Field references. It basically just stores declaring class
* and field name.
*/
private final static class Serialization
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected Class<?> clazz;
protected String name;
public Serialization(Field f) {
clazz = f.getDeclaringClass();
name = f.getName();
}
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.*;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonMapFormatVisitor;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.ContainerSerializer;
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
import com.fasterxml.jackson.databind.ser.PropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.ArrayBuilders;
/**
* Standard serializer implementation for serializing {link java.util.Map} types.
*<p>
* Note: about the only configurable setting currently is ability to filter out
* entries with specified names.
*/
@JacksonStdImpl
public class MapSerializer
extends ContainerSerializer<Map<?,?>>
implements ContextualSerializer
{
private static final long serialVersionUID = 1L;
protected final static JavaType UNSPECIFIED_TYPE = TypeFactory.unknownType();
/**
* Map-valued property being serialized with this instance
*/
protected final BeanProperty _property;
/**
* Set of entries to omit during serialization, if any
*/
protected final HashSet<String> _ignoredEntries;
/**
* Whether static types should be used for serialization of values
* or not (if not, dynamic runtime type is used)
*/
protected final boolean _valueTypeIsStatic;
/**
* Declared type of keys
*/
protected final JavaType _keyType;
/**
* Declared type of contained values
*/
protected final JavaType _valueType;
/**
* Key serializer to use, if it can be statically determined
*/
protected JsonSerializer<Object> _keySerializer;
/**
* Value serializer to use, if it can be statically determined
*/
protected JsonSerializer<Object> _valueSerializer;
/**
* Type identifier serializer used for values, if any.
*/
protected final TypeSerializer _valueTypeSerializer;
/**
* If value type can not be statically determined, mapping from
* runtime value types to serializers are stored in this object.
*/
protected PropertySerializerMap _dynamicValueSerializers;
/**
* Id of the property filter to use, if any; null if none.
*
* @since 2.3
*/
protected final Object _filterId;
/**
* Flag set
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonStringFormatVisitor;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonValueFormat;
@JacksonStdImpl
@SuppressWarnings("serial")
public class SqlTimeSerializer
extends StdScalarSerializer<java.sql.Time>
{
public SqlTimeSerializer() { super(java.sql.Time.class); }
@Override
public void serialize(java.sql.Time value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
jgen.writeString(value.toString());
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("string", true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
JsonStringFormatVisitor v2 = (visitor == null) ? null : visitor.expectStringFormat(typeHint);
if (v2 != null) {
v2.format(JsonValueFormat.DATE_TIME);
}
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.JsonParser.NumberType;
import com.fasterxml.jackson.core.io.NumberInput;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.Converter;
/**
* Base class for common deserializers. Contains shared
* base functionality for dealing with primitive values, such
* as (re)parsing from String.
*/
public abstract class StdDeserializer<T>
extends JsonDeserializer<T>
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Bitmask that covers {@link DeserializationFeature#USE_BIG_INTEGER_FOR_INTS}
* and {@link DeserializationFeature#USE_LONG_FOR_INTS}, used for more efficient
* cheks when coercing integral values for untyped deserialization.
*
* @since 2.6
*/
protected final static int F_MASK_INT_COERCIONS =
DeserializationFeature.USE_BIG_INTEGER_FOR_INTS.getMask()
| DeserializationFeature.USE_LONG_FOR_INTS.getMask();
/**
* Type of values this deserializer handles: sometimes
* exact types, other time most specific supertype of
* types deserializer handles (which may be as generic
* as {@link Object} in some case)
*/
final protected Class<?> _valueClass;
protected StdDeserializer(Class<?> vc) {
_valueClass = vc;
}
protected StdDeserializer(JavaType valueType) {
_valueClass = (valueType == null) ? null : valueType.getRawClass();
}
/**
* Copy-constructor for sub-classes to use, most often when creating
* new instances for {@link com.fasterxml.jackson.databind.deser.ContextualDeserializer}.
*
* @since 2.5
*/
protected StdDeserializer(StdDeserializer<?> src) {
_valueClass = src._valueClass;
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public Class<?> handledType() { return _valueClass; }
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* @deprecated Since 2.3 use {@link #handledType} instead
*/
@Deprecated
public final Class<?> getValueClass() { return _valueClass; }
/**
* Exact structured type deserializer handles, if known.
*<p>
* Default implementation just returns null.
*/
public JavaType getValueType() { return null; }
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>not a valid double value");
}
if (t == JsonToken.VALUE_NULL) {
return 0.0;
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final double parsed = _parseDoublePrimitive(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Byte' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected java.util.Date _parseDate(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT) {
return new java.util.Date(jp.getLongValue());
}
if (t == JsonToken.VALUE_NULL) {
return (java.util.Date) getNullValue(ctxt);
}
if (t == JsonToken.VALUE_STRING) {
String value = null;
try {
// As per [JACKSON-203], take empty Strings to mean
value = jp.getText().trim();
if (value.length() == 0) {
return (Date) getEmptyValue(ctxt);
}
if (_hasTextualNull(value)) {
return (java.util.Date) getNullValue(ctxt);
}
return ctxt.parseDate(value);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(value, _valueClass,
"not a valid representation (error: "+iae.getMessage()+")");
}
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final Date parsed = _parseDate(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'java.util.Date' value but there was more than a single value in the array");
}
return parsed;
}
throw ctxt.mappingException(_valueClass, t);
}
/**
* Helper method for encapsulating calls to low-level double value parsing; single place
* just because we need a work-around that must be applied to all calls.
*/
protected final static double parseDouble(String numStr) throws NumberFormatException
{
// [JACKSON-486]: avoid some nasty float representations... but should it be MIN_NORMAL or MIN_VALUE?
// for now, MIN_VALUE,
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdResolver;
import com.fasterxml.jackson.annotation.SimpleObjectIdResolver;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
/**
* Object that knows how to deserialize Object Ids.
*/
public class ObjectIdReader
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected final JavaType _idType;
public final PropertyName propertyName;
/**
* Blueprint generator instance: actual instance will be
* fetched from {@link SerializerProvider} using this as
* the key.
*/
public final ObjectIdGenerator<?> generator;
public final ObjectIdResolver resolver;
/**
* Deserializer used for deserializing id values.
*/
protected final JsonDeserializer<Object> _deserializer;
public final SettableBeanProperty idProperty;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
@SuppressWarnings("unchecked")
protected ObjectIdReader(JavaType t, PropertyName propName, ObjectIdGenerator<?> gen,
JsonDeserializer<?> deser, SettableBeanProperty idProp, ObjectIdResolver resolver)
{
_idType = t;
propertyName = propName;
generator = gen;
this.resolver = resolver;
_deserializer = (JsonDeserializer<Object>) deser;
idProperty = idProp;
}
@Deprecated // since 2.4
protected ObjectIdReader(JavaType t, PropertyName propName, ObjectIdGenerator<?> gen,
JsonDeserializer<?> deser, SettableBeanProperty idProp)
{
this(t,propName, gen, deser, idProp, new SimpleObjectIdResolver());
}
/**
* Factory method called by {@link com.fasterxml.jackson.databind.ser.std.BeanSerializerBase}
* with the initial information based on standard settings for the type
* for which serializer is being built.
*/
public static ObjectIdReader construct(JavaType idType, PropertyName propName,
ObjectIdGenerator<?> generator, JsonDeserializer<?> deser,
SettableBeanProperty idProp, ObjectIdResolver resolver)
{
return new ObjectIdReader(idType, propName, generator, deser, idProp, resolver);
}
@Deprecated // since 2.4
public static ObjectIdReader construct(JavaType idType, PropertyName propName,
ObjectIdGenerator<?> generator, JsonDeserializer<?> deser,
SettableBeanProperty idProp)
{
return construct(idType, propName, generator, deser, idProp, new SimpleObjectIdResolver());
}
/*
/**********************************************************
/* API
/**********************************************************
*/
public JsonDeserializer<Object> getDeserializer() {
return _deserializer;
}
public JavaType getIdType() {
return _idType;
}
/**
* Convenience method, equivalent to calling:
*<code>
* reader
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.ObjectBuffer;
/**
* Separate implementation for serializing String arrays (instead of
* using {@link ObjectArrayDeserializer}.
* Used if (and only if) no custom value deserializers are used.
*/
@JacksonStdImpl
public final class StringArrayDeserializer
extends StdDeserializer<String[]>
implements ContextualDeserializer
{
private static final long serialVersionUID = 1L;
public final static StringArrayDeserializer instance = new StringArrayDeserializer();
/**
* Value serializer to use, if not the standard one (which is inlined)
*/
protected JsonDeserializer<String> _elementDeserializer;
public StringArrayDeserializer() {
super(String[].class);
_elementDeserializer = null;
}
@SuppressWarnings("unchecked")
protected StringArrayDeserializer(JsonDeserializer<?> deser) {
super(String[].class);
_elementDeserializer = (JsonDeserializer<String>) deser;
}
@Override
public String[] deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// Ok: must point to START_ARRAY (or equivalent)
if (!jp.isExpectedStartArrayToken()) {
return handleNonArray(jp, ctxt);
}
if (_elementDeserializer != null) {
return _deserializeCustom(jp, ctxt);
}
final ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] chunk = buffer.resetAndStart();
int ix = 0;
try {
while (true) {
String value = jp.nextTextValue();
if (value == null) {
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.END_ARRAY) {
break;
}
if (t != JsonToken.VALUE_NULL) {
value = _parseString(jp, ctxt);
}
}
if (ix >= chunk.length) {
chunk = buffer.appendCompletedChunk(chunk);
ix = 0;
}
chunk[ix++] = value;
}
} catch (Exception e) {
throw JsonMappingException.wrapWithPath(e, chunk, buffer.bufferedSize() + ix);
}
String[] result = buffer.completeAndClearBuffer(chunk, ix, String.class);
ctxt.returnObjectBuffer(buffer);
return result;
}
/**
* Offlined version used when we do not use the default deserialization method.
*/
protected final String[] _deserializeCustom(JsonParser jp, DeserializationContext ctxt) throws IOException
{
final ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] chunk = buffer.resetAndStart();
final JsonDeserializer<String>
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.Collection;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
import com.fasterxml.jackson.databind.introspect.AnnotatedWithParams;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
/**
* Specifically optimized version for {@link java.util.Collection}s
* that contain String values; reason is that this is a very common
* type and we can make use of the fact that Strings are final.
*/
@JacksonStdImpl
public final class StringCollectionDeserializer
extends ContainerDeserializerBase<Collection<String>>
implements ContextualDeserializer
{
private static final long serialVersionUID = 1L;
// // Configuration
protected final JavaType _collectionType;
/**
* Value deserializer to use, if NOT the standard one
* (if it is, will be null).
*/
protected final JsonDeserializer<String> _valueDeserializer;
// // Instance construction settings:
/**
* Instantiator used in case custom handling is needed for creation.
*/
protected final ValueInstantiator _valueInstantiator;
/**
* Deserializer that is used iff delegate-based creator is
* to be used for deserializing from JSON Object.
*/
protected final JsonDeserializer<Object> _delegateDeserializer;
// NOTE: no PropertyBasedCreator, as JSON Arrays have no properties
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public StringCollectionDeserializer(JavaType collectionType,
JsonDeserializer<?> valueDeser, ValueInstantiator valueInstantiator)
{
this(collectionType, valueInstantiator, null, valueDeser);
}
@SuppressWarnings("unchecked")
protected StringCollectionDeserializer(JavaType collectionType,
ValueInstantiator valueInstantiator, JsonDeserializer<?> delegateDeser,
JsonDeserializer<?> valueDeser)
{
super(collectionType);
_collectionType = collectionType;
_valueDeserializer = (JsonDeserializer<String>) valueDeser;
_valueInstantiator = valueInstantiator;
_delegateDeserializer = (JsonDeserializer<Object>) delegateDeser;
}
protected StringCollectionDeserializer withResolved(JsonDeserializer<?> delegateDeser,
JsonDeserializer<?> valueDeser)
{
if ((_valueDeserializer == valueDeser) && (_delegateDeserializer == delegateDeser)) {
return this;
}
return new StringCollectionDeserializer(_collectionType,
_valueInstantiator, delegateDeser, valueDeser);
}
@Override // since 2.5
public boolean isCachable() {
// 26-Mar-2015, tatu: Important: prevent caching if custom deserializers are involved
return (_valueDeserializer == null) && (_delegateDeserializer == null);
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import java.util.*;
import com.fasterxml.jackson.databind.JavaType;
/**
* Type that represents Map-like types; things that consist of key/value pairs but that
* do not necessarily implement {@link java.util.Map}, but that do not have enough
* introspection functionality to allow for some level of generic handling.
* This specifically allows framework to check for configuration and annotation
* settings used for Map types, and pass these to custom handlers that may be more
* familiar with actual type.
*/
public class MapLikeType extends TypeBase
{
private static final long serialVersionUID = 1L;
/**
* Type of keys of Map.
*/
protected final JavaType _keyType;
/**
* Type of values of Map.
*/
protected final JavaType _valueType;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
protected MapLikeType(Class<?> mapType, JavaType keyT, JavaType valueT,
Object valueHandler, Object typeHandler, boolean asStatic)
{
super(mapType, keyT.hashCode() ^ valueT.hashCode(), valueHandler, typeHandler, asStatic);
_keyType = keyT;
_valueType = valueT;
}
public static MapLikeType construct(Class<?> rawType, JavaType keyT, JavaType valueT)
{
// nominally component types will be just Object.class
return new MapLikeType(rawType, keyT, valueT, null, null, false);
}
@Override
protected JavaType _narrow(Class<?> subclass) {
return new MapLikeType(subclass, _keyType, _valueType, _valueHandler, _typeHandler, _asStatic);
}
@Override
public JavaType narrowContentsBy(Class<?> contentClass)
{
// Can do a quick check first:
if (contentClass == _valueType.getRawClass()) {
return this;
}
return new MapLikeType(_class, _keyType, _valueType.narrowBy(contentClass),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public JavaType widenContentsBy(Class<?> contentClass)
{
if (contentClass == _valueType.getRawClass()) {
return this;
}
return new MapLikeType(_class, _keyType, _valueType.widenBy(contentClass),
_valueHandler, _typeHandler, _asStatic);
}
public JavaType narrowKey(Class<?> keySubclass)
{
// Can do a quick check first:
if (keySubclass == _keyType.getRawClass()) {
return this;
}
return new MapLikeType(_class, _keyType.narrowBy(keySubclass), _valueType,
_valueHandler, _typeHandler, _asStatic);
}
public JavaType widenKey(Class<?> keySubclass)
{
// Can do a quick check first:
if (keySubclass == _keyType.getRawClass()) {
return this;
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.cfg;
import java.util.*;
/**
* Helper class used for storing and accessing per-call attributes.
* Storage is two-layered: at higher precedence, we have actual per-call
* attributes; and at lower precedence, default attributes that may be
* defined for Object readers and writers.
*<p>
* Note that the way mutability is implemented differs between kinds
* of attributes, to account for thread-safety: per-call attributes
* are handled assuming that instances are never shared, whereas
* changes to per-reader/per-writer attributes are made assuming
* sharing, by creating new copies instead of modifying state.
* This allows sharing of default values without per-call copying, but
* requires two-level lookup on access.
*
* @since 2.3
*/
public abstract class ContextAttributes
{
public static ContextAttributes getEmpty() {
return Impl.getEmpty();
}
/*
/**********************************************************
/* Per-reader/writer access
/**********************************************************
*/
public abstract ContextAttributes withSharedAttribute(Object key, Object value);
public abstract ContextAttributes withSharedAttributes(Map<Object,Object> attributes);
public abstract ContextAttributes withoutSharedAttribute(Object key);
/*
/**********************************************************
/* Per-operation (serialize/deserialize) access
/**********************************************************
*/
/**
* Accessor for value of specified attribute
*/
public abstract Object getAttribute(Object key);
/**
* Mutator used during call (via context) to set value of "non-shared"
* part of attribute set.
*/
public abstract ContextAttributes withPerCallAttribute(Object key, Object value);
/*
/**********************************************************
/* Default implementation
/**********************************************************
*/
public static class Impl extends ContextAttributes
implements java.io.Serializable // just so ObjectReader/ObjectWriter can retain configs
{
private static final long serialVersionUID = 1L;
protected final static Impl EMPTY = new Impl(Collections.emptyMap());
protected final static Object NULL_SURROGATE = new Object();
/**
* Shared attributes that we can not modify in-place.
*/
protected final Map<Object,Object> _shared;
/**
* Per-call attributes that we can directly modify, since they are not
* shared between threads.
*/
protected transient Map<Object,Object> _nonShared;
/*
/**********************************************************
/* Construction, factory methods
/**********************************************************
*/
protected Impl(Map<Object,Object> shared) {
_shared = shared;
_nonShared = null;
}
protected Impl(Map<Object,Object> shared, Map<Object,Object> nonShared) {
_shared = shared;
_nonShared = nonShared;
}
public static ContextAttributes getEmpty() {
return EMPTY;
}
/*
/**********************************************************
/* Per-reader/writer mutant factories
/**********************************************************
*/
@Override
public ContextAttributes withSharedAttribute(Object key, Object value)
{
Map<
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.NameTransformer;
import java.io.IOException;
public class UnwrappingBeanSerializer
extends BeanSerializerBase
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Transformer used to add prefix and/or suffix for properties
* of unwrapped POJO.
*/
protected final NameTransformer _nameTransformer;
/*
/**********************************************************
/* Life-cycle: constructors
/**********************************************************
*/
/**
* Constructor used for creating unwrapping instance of a
* standard <code>BeanSerializer</code>
*/
public UnwrappingBeanSerializer(BeanSerializerBase src, NameTransformer transformer) {
super(src, transformer);
_nameTransformer = transformer;
}
public UnwrappingBeanSerializer(UnwrappingBeanSerializer src,
ObjectIdWriter objectIdWriter) {
super(src, objectIdWriter);
_nameTransformer = src._nameTransformer;
}
public UnwrappingBeanSerializer(UnwrappingBeanSerializer src,
ObjectIdWriter objectIdWriter, Object filterId) {
super(src, objectIdWriter, filterId);
_nameTransformer = src._nameTransformer;
}
protected UnwrappingBeanSerializer(UnwrappingBeanSerializer src, String[] toIgnore) {
super(src, toIgnore);
_nameTransformer = src._nameTransformer;
}
/*
/**********************************************************
/* Life-cycle: factory methods, fluent factories
/**********************************************************
*/
@Override
public JsonSerializer<Object> unwrappingSerializer(NameTransformer transformer) {
// !!! 23-Jan-2012, tatu: Should we chain transformers?
return new UnwrappingBeanSerializer(this, transformer);
}
@Override
public boolean isUnwrappingSerializer() {
return true; // sure is
}
@Override
public BeanSerializerBase withObjectIdWriter(ObjectIdWriter objectIdWriter) {
return new UnwrappingBeanSerializer(this, objectIdWriter);
}
@Override
public BeanSerializerBase withFilterId(Object filterId) {
return new UnwrappingBeanSerializer(this, _objectIdWriter, filterId);
}
@Override
protected BeanSerializerBase withIgnorals(String[] toIgnore) {
return new UnwrappingBeanSerializer(this, toIgnore);
}
/**
* JSON Array output can not be done if unwrapping operation is
* requested; so implementation will simply return 'this'.
*/
@Override
protected BeanSerializerBase asArraySerializer() {
return this;
}
/*
/**********************************************************
/* JsonSerializer implementation that differs between impls
/**********************************************************
*/
/**
* Main serialization method that will delegate actual output to
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.exc;
import java.util.*;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonMappingException;
/**
* Specialized {@link JsonMappingException} sub-class used to indicate
* case where an explicitly ignored property is encountered, and mapper
* is configured to consider this an error.
*
* @since 2.3
*/
public class IgnoredPropertyException
extends PropertyBindingException
{
private static final long serialVersionUID = 1L;
public IgnoredPropertyException(String msg, JsonLocation loc,
Class<?> referringClass, String propName,
Collection<Object> propertyIds)
{
super(msg, loc, referringClass, propName, propertyIds);
}
/**
* Factory method used for constructing instances of this exception type.
*
* @param jp Underlying parser used for reading input being used for data-binding
* @param fromObjectOrClass Reference to either instance of problematic type (
* if available), or if not, type itself
* @param propertyName Name of unrecognized property
* @param propertyIds (optional, null if not available) Set of properties that
* type would recognize, if completely known: null if set can not be determined.
*/
public static IgnoredPropertyException from(JsonParser jp,
Object fromObjectOrClass, String propertyName,
Collection<Object> propertyIds)
{
if (fromObjectOrClass == null) {
throw new IllegalArgumentException();
}
Class<?> ref;
if (fromObjectOrClass instanceof Class<?>) {
ref = (Class<?>) fromObjectOrClass;
} else {
ref = fromObjectOrClass.getClass();
}
String msg = "Ignored field \""+propertyName+"\" (class "+ref.getName()
+") encountered; mapper configured not to allow this";
IgnoredPropertyException e = new IgnoredPropertyException(msg,
jp.getCurrentLocation(), ref, propertyName, propertyIds);
// but let's also ensure path includes this last (missing) segment
e.prependPath(fromObjectOrClass, propertyName);
return e;
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.cfg;
import java.text.DateFormat;
import java.util.Locale;
import java.util.TimeZone;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.Base64Variant;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair;
import com.fasterxml.jackson.databind.introspect.ClassIntrospector;
import com.fasterxml.jackson.databind.introspect.VisibilityChecker;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.StdDateFormat;
/**
* Immutable container class used to store simple configuration
* settings. Since instances are fully immutable, instances can
* be freely shared and used without synchronization.
*/
public final class BaseSettings
implements java.io.Serializable
{
// for 2.6
private static final long serialVersionUID = 1L;
/*
/**********************************************************
/* Configuration settings; introspection, related
/**********************************************************
*/
/**
* Introspector used to figure out Bean properties needed for bean serialization
* and deserialization. Overridable so that it is possible to change low-level
* details of introspection, like adding new annotation types.
*/
protected final ClassIntrospector _classIntrospector;
/**
* Introspector used for accessing annotation value based configuration.
*/
protected final AnnotationIntrospector _annotationIntrospector;
/**
* Object used for determining whether specific property elements
* (method, constructors, fields) can be auto-detected based on
* their visibility (access modifiers). Can be changed to allow
* different minimum visibility levels for auto-detection. Note
* that this is the global handler; individual types (classes)
* can further override active checker used (using
* {@link JsonAutoDetect} annotation)
*/
protected final VisibilityChecker<?> _visibilityChecker;
/**
* Custom property naming strategy in use, if any.
*/
protected final PropertyNamingStrategy _propertyNamingStrategy;
/**
* Specific factory used for creating {@link JavaType} instances;
* needed to allow modules to add more custom type handling
* (mostly to support types of non-Java JVM languages)
*/
protected final TypeFactory _typeFactory;
/*
/**********************************************************
/* Configuration settings; type resolution
/**********************************************************
*/
/**
* Type information handler used for "untyped" values (ones declared
* to have type <code>Object.class</code>)
*/
protected final TypeResolverBuilder<?> _typeResolverBuilder;
/*
/**********************************************************
/* Configuration settings; other
/**********************************************************
*/
/**
* Custom date format to use for de-serialization. If specified, will be
* used instead of {@link com.fasterxml.jackson.databind.util.StdDateFormat
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import java.lang.reflect.Array;
import com.fasterxml.jackson.databind.JavaType;
/**
* Array types represent Java arrays, both primitive and object valued.
* Further, Object-valued arrays can have element type of any other
* legal {@link JavaType}.
*/
public final class ArrayType
extends TypeBase
{
private static final long serialVersionUID = 1L;
/**
* Type of elements in the array.
*/
protected final JavaType _componentType;
/**
* We will also keep track of shareable instance of empty array,
* since it usually needs to be constructed any way; and because
* it is essentially immutable and thus can be shared.
*/
protected final Object _emptyArray;
protected ArrayType(JavaType componentType, Object emptyInstance,
Object valueHandler, Object typeHandler, boolean asStatic)
{
super(emptyInstance.getClass(), componentType.hashCode(),
valueHandler, typeHandler, asStatic);
_componentType = componentType;
_emptyArray = emptyInstance;
}
public static ArrayType construct(JavaType componentType,
Object valueHandler, Object typeHandler)
{
/* This is bit messy: there is apparently no other way to
* reconstruct actual concrete/raw array class from component
* type, than to construct an instance, get class (same is
* true for GenericArracyType as well; hence we won't bother
* passing that in).
*/
Object emptyInstance = Array.newInstance(componentType.getRawClass(), 0);
return new ArrayType(componentType, emptyInstance, null, null, false);
}
@Override
public ArrayType withTypeHandler(Object h)
{
if (h == _typeHandler) {
return this;
}
return new ArrayType(_componentType, _emptyArray, _valueHandler, h, _asStatic);
}
@Override
public ArrayType withContentTypeHandler(Object h)
{
if (h == _componentType.<Object>getTypeHandler()) {
return this;
}
return new ArrayType(_componentType.withTypeHandler(h), _emptyArray,
_valueHandler, _typeHandler, _asStatic);
}
@Override
public ArrayType withValueHandler(Object h) {
if (h == _valueHandler) {
return this;
}
return new ArrayType(_componentType, _emptyArray, h, _typeHandler,_asStatic);
}
@Override
public ArrayType withContentValueHandler(Object h) {
if (h == _componentType.<Object>getValueHandler()) {
return this;
}
return new ArrayType(_componentType.withValueHandler(h), _emptyArray,
_valueHandler, _typeHandler, _asStatic);
}
@Override
public ArrayType withStaticTyping() {
if (_asStatic) {
return this;
}
return new ArrayType(_componentType.withStaticTyping(),
_emptyArray, _valueHandler
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import java.lang.reflect.Modifier;
import com.fasterxml.jackson.core.type.ResolvedType;
import com.fasterxml.jackson.databind.type.TypeFactory;
/**
* Base class for type token classes used both to contain information
* and as keys for deserializers.
*<p>
* Instances can (only) be constructed by
* <code>com.fasterxml.jackson.databind.type.TypeFactory</code>.
*<p>
* Since 2.2 this implements {@link java.lang.reflect.Type} to allow
* it to be pushed through interfaces that only expose that type.
*/
public abstract class JavaType
extends ResolvedType
implements java.io.Serializable, // 2.1
java.lang.reflect.Type // 2.2
{
private static final long serialVersionUID = 1;
/**
* This is the nominal type-erased Class that would be close to the
* type represented (but not exactly type, due to type erasure: type
* instance may have more information on this).
* May be an interface or abstract class, so instantiation
* may not be possible.
*/
protected final Class<?> _class;
protected final int _hash;
/**
* Optional handler (codec) that can be attached to indicate
* what to use for handling (serializing, deserializing) values of
* this specific type.
*<p>
* Note: untyped (i.e. caller has to cast) because it is used for
* different kinds of handlers, with unrelated types.
*/
protected final Object _valueHandler;
/**
* Optional handler that can be attached to indicate how to handle
* additional type metadata associated with this type.
*<p>
* Note: untyped (i.e. caller has to cast) because it is used for
* different kinds of handlers, with unrelated types.
*/
protected final Object _typeHandler;
/**
* Whether entities defined with this type should be handled using
* static typing (as opposed to dynamic runtime type) or not.
*
* @since 2.2
*/
protected final boolean _asStatic;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
/**
* @param raw "Raw" (type-erased) class for this type
* @param additionalHash Additional hash code to use, in addition
* to hash code of the class name
*/
protected JavaType(Class<?> raw, int additionalHash,
Object valueHandler, Object typeHandler, boolean asStatic)
{
_class = raw;
_hash = raw.getName().hashCode() + additionalHash;
_valueHandler = valueHandler;
_typeHandler = typeHandler;
_asStatic = asStatic;
}
/**
* "Copy method" that will construct a new instance that is identical to
* this instance, except that it will have specified type handler assigned.
*
* @return Newly created type instance
*/
public abstract JavaType
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser;
import java.io.IOException;
import java.lang.annotation.Annotation;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.Annotations;
/**
* This concrete sub-class implements property that is passed
* via Creator (constructor or static factory method).
* It is not a full-featured implementation in that its set method
* should never be called -- instead, value must separately passed.
*<p>
* Note on injectable values: unlike with other mutators, where
* deserializer and injecting are separate, here we treat the two as related
* things. This is necessary to add proper priority, as well as to simplify
* coordination.
*/
public class CreatorProperty
extends SettableBeanProperty
{
private static final long serialVersionUID = 1L;
/**
* Placeholder that represents constructor parameter, when it is created
* from actual constructor.
* May be null when a synthetic instance is created.
*/
protected final AnnotatedParameter _annotated;
/**
* Id of value to inject, if value injection should be used for this parameter
* (in addition to, or instead of, regular deserialization).
*/
protected final Object _injectableValueId;
/**
* @since 2.1
*/
protected final int _creatorIndex;
/**
* In special cases, when implementing "updateValue", we can not use
* constructors or factory methods, but have to fall back on using a
* setter (or mutable field property). If so, this refers to that fallback
* accessor.
*<p>
* Mutable only to allow setting after construction, but must be strictly
* set before any use.
*
* @since 2.3
*/
protected SettableBeanProperty _fallbackSetter;
/**
* @param name Name of the logical property
* @param type Type of the property, used to find deserializer
* @param typeDeser Type deserializer to use for handling polymorphic type
* information, if one is needed
* @param contextAnnotations Contextual annotations (usually by class that
* declares creator [constructor, factory method] that includes
* this property)
* @param param Representation of property, constructor or factory
* method parameter; used for accessing annotations of the property
* @param index Index of this property within creator invocation
*
* @since 2.3
*/
public CreatorProperty(PropertyName name, JavaType type, PropertyName wrapperName,
TypeDeserializer typeDeser,
Annotations contextAnnotations, AnnotatedParameter param,
int index, Object injectableValueId,
PropertyMetadata metadata)
{
super
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.lang.annotation.Annotation;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
/**
* Specialized {@link SettableBeanProperty} implementation used
* for virtual property that represents Object Id that is used
* for some POJO types (or properties).
*/
public final class ObjectIdValueProperty
extends SettableBeanProperty
{
private static final long serialVersionUID = 1L;
protected final ObjectIdReader _objectIdReader;
public ObjectIdValueProperty(ObjectIdReader objectIdReader,
PropertyMetadata metadata)
{
super(objectIdReader.propertyName, objectIdReader.getIdType(), metadata,
objectIdReader.getDeserializer());
_objectIdReader = objectIdReader;
}
protected ObjectIdValueProperty(ObjectIdValueProperty src, JsonDeserializer<?> deser)
{
super(src, deser);
_objectIdReader = src._objectIdReader;
}
protected ObjectIdValueProperty(ObjectIdValueProperty src, PropertyName newName) {
super(src, newName);
_objectIdReader = src._objectIdReader;
}
@Override
public ObjectIdValueProperty withName(PropertyName newName) {
return new ObjectIdValueProperty(this, newName);
}
@Override
public ObjectIdValueProperty withValueDeserializer(JsonDeserializer<?> deser) {
return new ObjectIdValueProperty(this, deser);
}
// // // BeanProperty impl
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return null;
}
@Override public AnnotatedMember getMember() { return null; }
/*
/**********************************************************
/* Deserialization methods
/**********************************************************
*/
@Override
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
Object instance) throws IOException
{
deserializeSetAndReturn(p, ctxt, instance);
}
@Override
public Object deserializeSetAndReturn(JsonParser p,
DeserializationContext ctxt, Object instance) throws IOException
{
// note: no null checks (unlike usually); deserializer should fail if one found
Object id = _valueDeserializer.deserialize(p, ctxt);
/* 02-Apr-2015, tatu: Actually, as per [databind#742], let it be;
* missing or null id is needed for some cases, such as cases where id
* will be generated externally, at a later point, and is not available
* quite yet. Typical use case is with DB inserts.
*/
if (id == null) {
return null;
}
ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver);
roid.bindItem(instance);
// also: may need to set a property value as well
SettableBeanProperty idProp = _objectIdReader.
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
/**
* We need a custom deserializer both because {@link ArrayBlockingQueue} has no
* default constructor AND because it has size limit used for constructing
* underlying storage automatically.
*/
public class ArrayBlockingQueueDeserializer
extends CollectionDeserializer
{
private static final long serialVersionUID = 1;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
/**
* Constructor used when creating contextualized instances.
*/
public ArrayBlockingQueueDeserializer(JavaType collectionType,
JsonDeserializer<Object> valueDeser, TypeDeserializer valueTypeDeser,
ValueInstantiator valueInstantiator,
JsonDeserializer<Object> delegateDeser)
{
super(collectionType, valueDeser, valueTypeDeser, valueInstantiator, delegateDeser);
}
/**
* Copy-constructor that can be used by sub-classes to allow
* copy-on-write styling copying of settings of an existing instance.
*/
protected ArrayBlockingQueueDeserializer(ArrayBlockingQueueDeserializer src) {
super(src);
}
/**
* Fluent-factory method call to construct contextual instance.
*/
@Override
@SuppressWarnings("unchecked")
protected ArrayBlockingQueueDeserializer withResolved(JsonDeserializer<?> dd,
JsonDeserializer<?> vd, TypeDeserializer vtd)
{
if ((dd == _delegateDeserializer) && (vd == _valueDeserializer) && (vtd == _valueTypeDeserializer)) {
return this;
}
return new ArrayBlockingQueueDeserializer(_collectionType,
(JsonDeserializer<Object>) vd, vtd,
_valueInstantiator, (JsonDeserializer<Object>) dd);
}
/*
/**********************************************************
/* JsonDeserializer API
/**********************************************************
*/
@SuppressWarnings("unchecked")
@Override
public Collection<Object> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
if (_delegateDeserializer != null) {
return (Collection<Object>) _valueInstantiator.createUsingDelegate(ctxt,
_delegateDeserializer.deserialize(jp, ctxt));
}
if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
String str = jp.getText();
if (str.length() == 0) {
return (Collection<Object>) _valueInstantiator.createFromString(ctxt, str);
}
}
return deserialize(jp, ctxt, null);
}
@Override
public Collection<Object> deserialize(JsonParser jp, DeserializationContext ctxt, Collection<Object> result0) throws IOException
{
// Ok: must point to START_ARRAY (or equivalent)
if (!jp.isExpectedStartArrayToken()) {
return handle
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.lang.annotation.Annotation;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.deser.UnresolvedForwardReference;
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.introspect.ObjectIdInfo;
public class ObjectIdReferenceProperty extends SettableBeanProperty
{
private static final long serialVersionUID = 1L;
private final SettableBeanProperty _forward;
public ObjectIdReferenceProperty(SettableBeanProperty forward, ObjectIdInfo objectIdInfo)
{
super(forward);
_forward = forward;
_objectIdInfo = objectIdInfo;
}
public ObjectIdReferenceProperty(ObjectIdReferenceProperty src, JsonDeserializer<?> deser)
{
super(src, deser);
_forward = src._forward;
_objectIdInfo = src._objectIdInfo;
}
public ObjectIdReferenceProperty(ObjectIdReferenceProperty src, PropertyName newName)
{
super(src, newName);
_forward = src._forward;
_objectIdInfo = src._objectIdInfo;
}
@Override
public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
return new ObjectIdReferenceProperty(this, deser);
}
@Override
public SettableBeanProperty withName(PropertyName newName) {
return new ObjectIdReferenceProperty(this, newName);
}
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return _forward.getAnnotation(acls);
}
@Override
public AnnotatedMember getMember() {
return _forward.getMember();
}
@Override
public int getCreatorIndex() {
return _forward.getCreatorIndex();
}
@Override
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object instance) throws IOException {
deserializeSetAndReturn(p, ctxt, instance);
}
@Override
public Object deserializeSetAndReturn(JsonParser p, DeserializationContext ctxt, Object instance) throws IOException
{
try {
return setAndReturn(instance, deserialize(p, ctxt));
} catch (UnresolvedForwardReference reference) {
boolean usingIdentityInfo = (_objectIdInfo != null) || (_valueDeserializer.getObjectIdReader() != null);
if (!usingIdentityInfo) {
throw JsonMappingException.from(p, "Unresolved forward reference but no identity info.", reference);
}
reference.getRoid().appendReferring(new PropertyReferring(this, reference, _type.getRawClass(), instance));
return null;
}
}
@Override
public void set(Object instance, Object value) throws IOException {
_forward.set(instance, value);
}
@Override
public Object setAndReturn(Object
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.type.TypeBindings;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.Converter;
/**
* Basic container for information gathered by {@link ClassIntrospector} to
* help in constructing serializers and deserializers.
* Note that the main implementation type is
* {@link com.fasterxml.jackson.databind.introspect.BasicBeanDescription},
* meaning that it is safe to upcast to this type.
*/
public abstract class BeanDescription
{
/*
/**********************************************************
/* Configuration
/**********************************************************
*/
/**
* Bean type information, including raw class and possible
* * generics information
*/
protected final JavaType _type;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
protected BeanDescription(JavaType type) {
_type = type;
}
/*
/**********************************************************
/* Simple accesors
/**********************************************************
*/
/**
* Method for accessing declared type of bean being introspected,
* including full generic type information (from declaration)
*/
public JavaType getType() { return _type; }
public Class<?> getBeanClass() { return _type.getRawClass(); }
/**
* Method for accessing low-level information about Class this
* item describes.
*/
public abstract AnnotatedClass getClassInfo();
/**
* Accessor for getting information about Object Id expected to
* be used for this POJO type, if any.
*/
public abstract ObjectIdInfo getObjectIdInfo();
/**
* Method for checking whether class being described has any
* annotations recognized by registered annotation introspector.
*/
public abstract boolean hasKnownClassAnnotations();
/**
* Accessor for type bindings that may be needed to fully resolve
* types of member object, such as return and argument types of
* methods and constructors, and types of fields.
*/
public abstract TypeBindings bindingsForBeanType();
/**
* Method for resolving given JDK type, using this bean as the
* generic type resolution context.
*/
public abstract JavaType resolveType(java.lang.reflect.Type jdkType);
/**
* Method for accessing collection of annotations the bean
* class has.
*/
public abstract Annotations getClassAnnotations();
/*
/**********************************************************
/* Basic API for finding properties
/**********************************************************
*/
/**
* @return Ordered Map with logical property name as key, and
* matching getter method as value.
*/
public abstract List<BeanPropertyDefinition> findProperties();
/**
* Method for locating all back-reference properties (setters, fields
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
public class StackTraceElementDeserializer
extends StdScalarDeserializer<StackTraceElement>
{
private static final long serialVersionUID = 1L;
public StackTraceElementDeserializer() { super(StackTraceElement.class); }
@Override
public StackTraceElement deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
JsonToken t = jp.getCurrentToken();
// Must get an Object
if (t == JsonToken.START_OBJECT) {
String className = "", methodName = "", fileName = "";
int lineNumber = -1;
while ((t = jp.nextValue()) != JsonToken.END_OBJECT) {
String propName = jp.getCurrentName();
if ("className".equals(propName)) {
className = jp.getText();
} else if ("fileName".equals(propName)) {
fileName = jp.getText();
} else if ("lineNumber".equals(propName)) {
if (t.isNumeric()) {
lineNumber = jp.getIntValue();
} else {
throw JsonMappingException.from(jp, "Non-numeric token ("+t+") for property 'lineNumber'");
}
} else if ("methodName".equals(propName)) {
methodName = jp.getText();
} else if ("nativeMethod".equals(propName)) {
// no setter, not passed via constructor: ignore
} else {
handleUnknownProperty(jp, ctxt, _valueClass, propName);
}
}
return new StackTraceElement(className, methodName, fileName, lineNumber);
} else if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final StackTraceElement value = deserialize(jp, ctxt);
if (jp.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'java.lang.StackTraceElement' value but there was more than a single value in the array"
);
}
return value;
}
throw ctxt.mappingException(_valueClass, t);
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.util.TokenBuffer;
/**
* We also want to directly support deserialization of {@link TokenBuffer}.
*<p>
* Note that we use scalar deserializer base just because we claim
* to be of scalar for type information inclusion purposes; actual
* underlying content can be of any (Object, Array, scalar) type.
*<p>
* Since 2.3, another important thing is that possible native ids
* (type id, object id) should be properly copied even when converting
* with {@link TokenBuffer}. Such ids are supported if (and only if!)
* source {@link JsonParser} supports them.
*/
@JacksonStdImpl
public class TokenBufferDeserializer extends StdScalarDeserializer<TokenBuffer> {
private static final long serialVersionUID = 1L;
public TokenBufferDeserializer() { super(TokenBuffer.class); }
@Override
public TokenBuffer deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return createBufferInstance(jp).deserialize(jp, ctxt);
}
protected TokenBuffer createBufferInstance(JsonParser jp) {
return new TokenBuffer(jp);
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
/**
* Key class, used as an efficient and accurate key
* for locating per-class values, such as
* {@link com.fasterxml.jackson.databind.JsonSerializer}s.
*<p>
* The reason for having a separate key class instead of
* directly using {@link Class} as key is mostly
* to allow for redefining <code>hashCode</code> method --
* for some strange reason, {@link Class} does not
* redefine {@link Object#hashCode} and thus uses identity
* hash, which is pretty slow. This makes key access using
* {@link Class} unnecessarily slow.
*<p>
* Note: since class is not strictly immutable, caller must
* know what it is doing, if changing field values.
*/
public final class ClassKey
implements Comparable<ClassKey>,
java.io.Serializable // since 2.1
{
private static final long serialVersionUID = 1L;
private String _className;
private Class<?> _class;
/**
* Let's cache hash code straight away, since we are
* almost certain to need it.
*/
private int _hashCode;
public ClassKey()
{
_class = null;
_className = null;
_hashCode = 0;
}
public ClassKey(Class<?> clz)
{
_class = clz;
_className = clz.getName();
_hashCode = _className.hashCode();
}
public void reset(Class<?> clz)
{
_class = clz;
_className = clz.getName();
_hashCode = _className.hashCode();
}
/*
/**********************************************************
/* Comparable
/**********************************************************
*/
@Override
public int compareTo(ClassKey other)
{
// Just need to sort by name, ok to collide (unless used in TreeMap/Set!)
return _className.compareTo(other._className);
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
ClassKey other = (ClassKey) o;
/* Is it possible to have different Class object for same name + class loader combo?
* Let's assume answer is no: if this is wrong, will need to uncomment following functionality
*/
/*
return (other._className.equals(_className))
&& (other._class.getClassLoader() == _class.getClassLoader());
*/
return other._class == _class;
}
@Override public int hashCode() { return _hashCode; }
@Override public String toString() { return _className; }
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.BeanProperty;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.deser.ResolvableDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.ObjectBuffer;
/**
* Deserializer implementation that is used if it is necessary to bind content of
* "unknown" type; something declared as basic {@link java.lang.Object}
* (either explicitly, or due to type erasure).
* If so, "natural" mapping is used to convert JSON values to their natural
* Java object matches: JSON arrays to Java {@link java.util.List}s (or, if configured,
* Object[]), JSON objects to {@link java.util.Map}s, numbers to
* {@link java.lang.Number}s, booleans to {@link java.lang.Boolean}s and
* strings to {@link java.lang.String} (and nulls to nulls).
*/
@JacksonStdImpl
public class UntypedObjectDeserializer
extends StdDeserializer<Object>
implements ResolvableDeserializer, ContextualDeserializer
{
private static final long serialVersionUID = 1L;
protected final static Object[] NO_OBJECTS = new Object[0];
/**
* @deprecated Since 2.3, construct a new instance, needs to be resolved
*/
@Deprecated
public final static UntypedObjectDeserializer instance = new UntypedObjectDeserializer(null, null);
/*
/**********************************************************
/* Possible custom deserializer overrides we need to use
/**********************************************************
*/
protected JsonDeserializer<Object> _mapDeserializer;
protected JsonDeserializer<Object> _listDeserializer;
protected JsonDeserializer<Object> _stringDeserializer;
protected JsonDeserializer<Object> _numberDeserializer;
/**
* If {@link java.util.List} has been mapped to non-default implementation,
* we'll store type here
*
* @since 2.6
*/
protected JavaType _listType;
/**
* If {@link java.util.Map} has been mapped to non-default implementation,
* we'll store type here
*
* @since 2.6
*/
protected JavaType _mapType;
/**
* @deprecated Since 2.6 use variant takes
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS> JsonToken.END_ARRAY) {
return NO_OBJECTS;
}
ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] values = buffer.resetAndStart();
int ptr = 0;
do {
Object value = deserialize(jp, ctxt);
if (ptr >= values.length) {
values = buffer.appendCompletedChunk(values);
ptr = 0;
}
values[ptr++] = value;
} while (jp.nextToken() != JsonToken.END_ARRAY);
return buffer.completeAndClearBuffer(values, ptr);
}
/*
/**********************************************************
/* Separate "vanilla" implementation for common case of
/* no custom deserializer overrides
/**********************************************************
*/
@JacksonStdImpl
public static class Vanilla
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static Vanilla std = new Vanilla();
public Vanilla() { super(Object.class); }
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_OBJECT:
{
JsonToken t = p.nextToken();
if (t == JsonToken.END_OBJECT) {
return new LinkedHashMap<String,Object>(2);
}
}
case JsonTokenId.ID_FIELD_NAME:
return mapObject(p, ctxt);
case JsonTokenId.ID_START_ARRAY:
{
JsonToken t = p.nextToken();
if (t == JsonToken.END_ARRAY) { // and empty one too
if (ctxt.isEnabled(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY)) {
return NO_OBJECTS;
}
return new ArrayList<Object>(2);
}
}
if (ctxt.isEnabled(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY)) {
return mapArrayToArray(p, ctxt);
}
return mapArray(p, ctxt);
case JsonTokenId.ID_EMBEDDED_OBJECT:
return p.getEmbeddedObject();
case JsonTokenId.ID_STRING:
return p.getText();
case JsonTokenId.ID_NUMBER_INT:
if (ctxt.hasSomeOfFeatures(F_MASK_INT_COERCIONS)) {
return _coerceIntegral(p, ctxt);
}
return p.getNumberValue(); // should be optimal, whatever it is
case JsonTokenId.ID_NUMBER_FLOAT:
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
return p.getDecimalValue();
}
return Double.valueOf(p.getDoubleValue());
case JsonTokenId.ID_TRUE:
return Boolean.TRUE;
case JsonTokenId.ID_FALSE:
return Boolean.FALSE;
case JsonTokenId.ID_NULL: // should not get this but...
return null;
//case JsonTokenId.ID_END_ARRAY: // invalid
//case
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.introspect.AnnotatedField;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.Annotations;
/**
* This concrete sub-class implements property that is set
* directly assigning to a Field.
*/
public final class FieldProperty
extends SettableBeanProperty
{
private static final long serialVersionUID = 1L;
final protected AnnotatedField _annotated;
/**
* Actual field to set when deserializing this property.
* Transient since there is no need to persist; only needed during
* construction of objects.
*/
final protected transient Field _field;
public FieldProperty(BeanPropertyDefinition propDef, JavaType type,
TypeDeserializer typeDeser, Annotations contextAnnotations, AnnotatedField field)
{
super(propDef, type, typeDeser, contextAnnotations);
_annotated = field;
_field = field.getAnnotated();
}
protected FieldProperty(FieldProperty src, JsonDeserializer<?> deser) {
super(src, deser);
_annotated = src._annotated;
_field = src._field;
}
protected FieldProperty(FieldProperty src, PropertyName newName) {
super(src, newName);
_annotated = src._annotated;
_field = src._field;
}
/**
* Constructor used for JDK Serialization when reading persisted object
*/
protected FieldProperty(FieldProperty src)
{
super(src);
_annotated = src._annotated;
Field f = _annotated.getAnnotated();
if (f == null) {
throw new IllegalArgumentException("Missing field (broken JDK (de)serialization?)");
}
_field = f;
}
@Override
public FieldProperty withName(PropertyName newName) {
return new FieldProperty(this, newName);
}
@Override
public FieldProperty withValueDeserializer(JsonDeserializer<?> deser) {
return new FieldProperty(this, deser);
}
/*
/**********************************************************
/* BeanProperty impl
/**********************************************************
*/
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return (_annotated == null) ? null : _annotated.getAnnotation(acls);
}
@Override public AnnotatedMember getMember() { return _annotated; }
/*
/**********************************************************
/* Overridden methods
/**********************************************************
*/
@Override
public void deserializeAndSet(JsonParser jp,
DeserializationContext ctxt, Object instance) throws IOException
{
Object value =
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
// Simple placeholder
public class PropertyBasedObjectIdGenerator
extends ObjectIdGenerators.PropertyGenerator
{
private static final long serialVersionUID = 1L;
public PropertyBasedObjectIdGenerator(Class<?> scope) {
super(scope);
}
@Override
public Object generateId(Object forPojo) {
throw new UnsupportedOperationException();
}
@Override
public ObjectIdGenerator<Object> forScope(Class<?> scope) {
return (scope == _scope) ? this : new PropertyBasedObjectIdGenerator(scope);
}
@Override
public ObjectIdGenerator<Object> newForSerialization(Object context) {
return this;
}
@Override
public com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey key(Object key) {
if (key == null) {
return null;
}
// should we use general type for all; or type of property itself?
return new IdKey(getClass(), _scope, key);
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.databind.introspect.ObjectIdInfo;
import com.fasterxml.jackson.databind.ser.*;
public class PropertyBasedObjectIdGenerator
extends ObjectIdGenerators.PropertyGenerator
{
private static final long serialVersionUID = 1L;
protected final BeanPropertyWriter _property;
public PropertyBasedObjectIdGenerator(ObjectIdInfo oid, BeanPropertyWriter prop)
{
this(oid.getScope(), prop);
}
protected PropertyBasedObjectIdGenerator(Class<?> scope, BeanPropertyWriter prop)
{
super(scope);
_property = prop;
}
/**
* We must override this method, to prevent errors when scopes are the same,
* but underlying class (on which to access property) is different.
*/
@Override
public boolean canUseFor(ObjectIdGenerator<?> gen) {
if (gen.getClass() == getClass()) {
PropertyBasedObjectIdGenerator other = (PropertyBasedObjectIdGenerator) gen;
if (other.getScope() == _scope) {
/* 26-Jul-2012, tatu: This is actually not enough, because the property
* accessor within BeanPropertyWriter won't work for other property fields
* (see [https://github.com/FasterXML/jackson-module-jaxb-annotations/issues/9]
* for details).
* So we need to verify that underlying property is actually the same.
*/
return (other._property == _property);
}
}
return false;
}
@Override
public Object generateId(Object forPojo) {
try {
return _property.get(forPojo);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IllegalStateException("Problem accessing property '"
+_property.getName()+"': "+e.getMessage(), e);
}
}
@Override
public ObjectIdGenerator<Object> forScope(Class<?> scope) {
return (scope == _scope) ? this : new PropertyBasedObjectIdGenerator(scope, _property);
}
@Override
public ObjectIdGenerator<Object> newForSerialization(Object context) {
// No state, can return this
return this;
}
@Override
public com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey key(Object key) {
if (key == null) {
return null;
}
// should we use general type for all; or type of property itself?
return new IdKey(getClass(), _scope, key);
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS> boolean isGetterVisible(AnnotatedMethod m);
/**
* Method for checking whether given method is auto-detectable
* as is-getter, with respect to its visibility (not considering
* method signature or name, just visibility)
*/
public boolean isIsGetterVisible(Method m);
public boolean isIsGetterVisible(AnnotatedMethod m);
/**
* Method for checking whether given method is auto-detectable
* as setter, with respect to its visibility (not considering
* method signature or name, just visibility)
*/
public boolean isSetterVisible(Method m);
public boolean isSetterVisible(AnnotatedMethod m);
/**
* Method for checking whether given method is auto-detectable
* as Creator, with respect to its visibility (not considering
* method signature or name, just visibility)
*/
public boolean isCreatorVisible(Member m);
public boolean isCreatorVisible(AnnotatedMember m);
/**
* Method for checking whether given field is auto-detectable
* as property, with respect to its visibility (not considering
* method signature or name, just visibility)
*/
public boolean isFieldVisible(Field f);
public boolean isFieldVisible(AnnotatedField f);
/*
/********************************************************
/* Standard implementation suitable for basic use
/********************************************************
*/
/**
* Default standard implementation is purely based on visibility
* modifier of given class members, and its configured minimum
* levels.
* Implemented using "builder" (or "Fluent") pattern, whereas instances
* are immutable, and configuration is achieved by chainable factory
* methods. As a result, type is declared is funky recursive generic
* type, to allow for sub-classing of build methods with property type
* co-variance.
*<p>
* Note on <code>JsonAutoDetect</code> annotation: it is used to
* access default minimum visibility access definitions.
*/
@JsonAutoDetect(
getterVisibility = Visibility.PUBLIC_ONLY,
isGetterVisibility = Visibility.PUBLIC_ONLY,
setterVisibility = Visibility.ANY,
/**
* By default, all matching single-arg constructed are found,
* regardless of visibility. Does not apply to factory methods,
* they can not be auto-detected; ditto for multiple-argument
* constructors.
*/
creatorVisibility = Visibility.ANY,
fieldVisibility = Visibility.PUBLIC_ONLY
)
public static class Std
implements VisibilityChecker<Std>,
java.io.Serializable
{
private static final long serialVersionUID = 1;
/**
* This is the canonical base instance, configured with default
* visibility values
*/
protected final static Std DEFAULT = new Std(Std.class.getAnnotation(JsonAutoDetect.class));
protected final Visibility _getterMinLevel;
protected final Visibility _isGetterMinLevel;
protected final Visibility _setterMinLevel;
protected final Visibility _creatorMinLevel;
protected final Visibility _fieldMinLevel;
public static Std defaultInstance() { return DEFAULT; }
/**
* Constructor used for building instance that has minumum visibility
* levels as indicated by given annotation instance
*
* @param
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import java.util.Iterator;
import java.util.Map.Entry;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.io.SerializedString;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Variant of {@link BeanPropertyWriter} which will handle unwrapping
* of JSON Object (including of properties of Object within surrounding
* JSON object, and not as sub-object).
*/
public class UnwrappingBeanPropertyWriter
extends BeanPropertyWriter
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Transformer used to add prefix and/or suffix for properties
* of unwrapped POJO.
*/
protected final NameTransformer _nameTransformer;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public UnwrappingBeanPropertyWriter(BeanPropertyWriter base, NameTransformer unwrapper) {
super(base);
_nameTransformer = unwrapper;
}
protected UnwrappingBeanPropertyWriter(UnwrappingBeanPropertyWriter base, NameTransformer transformer,
SerializedString name) {
super(base, name);
_nameTransformer = transformer;
}
@Override
public UnwrappingBeanPropertyWriter rename(NameTransformer transformer)
{
String oldName = _name.getValue();
String newName = transformer.transform(oldName);
// important: combine transformers:
transformer = NameTransformer.chainedTransformer(transformer, _nameTransformer);
return _new(transformer, new SerializedString(newName));
}
/**
* Overridable factory method used by sub-classes
*
* @since 2.6.0
*/
protected UnwrappingBeanPropertyWriter _new(NameTransformer transformer, SerializedString newName)
{
return new UnwrappingBeanPropertyWriter(this, transformer, newName);
}
/*
/**********************************************************
/* Overrides, public methods
/**********************************************************
*/
@Override
public boolean isUnwrapping() {
return true;
}
@Override
public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov)
throws Exception
{
final Object value = get(bean);
if (value == null) {
// Hmmh. I assume we MUST pretty much suppress nulls, since we
// can't really unwrap them...
return;
}
JsonSerializer<Object> ser = _
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS> cached, and accessed
* using full (generics-aware) type information. This is different from
* caching of referenced types, which is more limited and is done only
* for a subset of all deserializer types. The main reason for difference
* is that at root-level there is no incoming reference (and hence no
* referencing property, no referral information or annotations to
* produce differing deserializers), and that the performance impact
* greatest at root level (since it'll essentially cache the full
* graph of deserializers involved).
*/
public class ObjectMapper
extends ObjectCodec
implements Versioned,
java.io.Serializable // as of 2.1
{
private static final long serialVersionUID = 1L;
/*
/**********************************************************
/* Helper classes, enums
/**********************************************************
*/
/**
* Enumeration used with {@link ObjectMapper#enableDefaultTyping()}
* to specify what kind of types (classes) default typing should
* be used for. It will only be used if no explicit type information
* is found, but this enumeration further limits subset of those types.
*<p>
* Since 2.4 there are special exceptions for JSON Tree model
* types (sub-types of {@link TreeNode}: default typing is never
* applied to them
* (see <a href="https://github.com/FasterXML/jackson-databind/issues/88">Issue#88</a> for details)
*/
public enum DefaultTyping {
/**
* This value means that only properties that have
* {@link java.lang.Object} as declared type (including
* generic types without explicit type) will use default
* typing.
*/
JAVA_LANG_OBJECT,
/**
* Value that means that default typing will be used for
* properties with declared type of {@link java.lang.Object}
* or an abstract type (abstract class or interface).
* Note that this does <b>not</b> include array types.
*<p>
* Since 2.4, this does NOT apply to {@link TreeNode} and its subtypes.
*/
OBJECT_AND_NON_CONCRETE,
/**
* Value that means that default typing will be used for
* all types covered by {@link #OBJECT_AND_NON_CONCRETE}
* plus all array types for them.
*<p>
* Since 2.4, this does NOT apply to {@link TreeNode} and its subtypes.
*/
NON_CONCRETE_AND_ARRAYS,
/**
* Value that means that default typing will be used for
* all non-final types, with exception of small number of
* "natural" types (String, Boolean, Integer, Double), which
* can be correctly inferred from JSON; as well as for
* all arrays of non-final types.
*<p>
* Since 2.4, this does NOT apply to {@link TreeNode} and its subtypes.
*/
NON_FINAL
}
/**
* Customized {@link TypeResolverBuilder} that provides type resolver build
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>ers
* used with so-called "default typing"
* (see {@link ObjectMapper#enableDefaultTyping()} for details).
*<p>
* Type resolver construction is based on configuration: implementation takes care
* of only providing builders in cases where type information should be applied.
* This is important since build calls may be sent for any and all types, and
* type information should NOT be applied to all of them.
*/
public static class DefaultTypeResolverBuilder
extends StdTypeResolverBuilder
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Definition of what types is this default typer valid for.
*/
protected final DefaultTyping _appliesFor;
public DefaultTypeResolverBuilder(DefaultTyping t) {
_appliesFor = t;
}
@Override
public TypeDeserializer buildTypeDeserializer(DeserializationConfig config,
JavaType baseType, Collection<NamedType> subtypes)
{
return useForType(baseType) ? super.buildTypeDeserializer(config, baseType, subtypes) : null;
}
@Override
public TypeSerializer buildTypeSerializer(SerializationConfig config,
JavaType baseType, Collection<NamedType> subtypes)
{
return useForType(baseType) ? super.buildTypeSerializer(config, baseType, subtypes) : null;
}
/**
* Method called to check if the default type handler should be
* used for given type.
* Note: "natural types" (String, Boolean, Integer, Double) will never
* use typing; that is both due to them being concrete and final,
* and since actual serializers and deserializers will also ignore any
* attempts to enforce typing.
*/
public boolean useForType(JavaType t)
{
switch (_appliesFor) {
case NON_CONCRETE_AND_ARRAYS:
while (t.isArrayType()) {
t = t.getContentType();
}
// fall through
case OBJECT_AND_NON_CONCRETE:
return t.isJavaLangObject()
|| (!t.isConcrete()
// [databind#88] Should not apply to JSON tree models:
&& !TreeNode.class.isAssignableFrom(t.getRawClass()));
case NON_FINAL:
while (t.isArrayType()) {
t = t.getContentType();
}
// [Issue#88] Should not apply to JSON tree models:
return !t.isFinal() && !TreeNode.class.isAssignableFrom(t.getRawClass());
default:
//case JAVA_LANG_OBJECT:
return t.isJavaLangObject();
}
}
}
/*
/**********************************************************
/* Internal constants, singletons
/**********************************************************
*/
// Quick little shortcut, to avoid having to use global TypeFactory instance...
private final static JavaType JSON_NODE_TYPE = SimpleType.constructUnsafe(JsonNode.class);
// 16-May-2009, tatu: Ditto ^^^
protected final static AnnotationIntrospector DEFAULT_ANNOTATION_
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.*;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.*;
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.VirtualBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.impl.AttributePropertyWriter;
import com.fasterxml.jackson.databind.ser.std.RawSerializer;
import com.fasterxml.jackson.databind.util.*;
/**
* {@link AnnotationIntrospector} implementation that handles standard
* Jackson annotations.
*/
public class JacksonAnnotationIntrospector
extends AnnotationIntrospector
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
public JacksonAnnotationIntrospector() { }
@Override
public Version version() {
return com.fasterxml.jackson.databind.cfg.PackageVersion.VERSION;
}
/*
/**********************************************************
/* General annotation properties
/**********************************************************
*/
/**
* Annotations with meta-annotation {@link JacksonAnnotationsInside}
* are considered bundles.
*/
@Override
public boolean isAnnotationBundle(Annotation ann) {
return ann.annotationType().getAnnotation(JacksonAnnotationsInside.class) != null;
}
/*
/**********************************************************
/* General annotations
/**********************************************************
*/
/**
* Since 2.6, we have supported use of {@link JsonProperty} for specifying
* explicit serialized name
*/
@Override
public String findEnumValue(Enum<?> value)
{
// 11-Jun-2015, tatu: As per [databind#677], need to allow explicit naming.
// Unfortunately can not quite use standard AnnotatedClass here (due to various
// reasons, including odd representation JVM uses); has to do for now
try {
// We know that values are actually static fields with matching name so:
Field f = value.getClass().getField(value.name());
if (f != null) {
JsonProperty prop = f.getAnnotation(JsonProperty.class);
String n = prop.value();
if (n != null && !n.isEmpty()) {
return n;
}
}
} catch (Exception e) {
// no such field, or access; neither which we can do much about
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdResolver;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.cfg.ContextAttributes;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId;
import com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.*;
/**
* Context for the process of deserialization a single root-level value.
* Used to allow passing in configuration settings and reusable temporary
* objects (scrap arrays, containers).
*<p>
* Instance life-cycle is such that an partially configured "blueprint" object
* is registered with {@link ObjectMapper} (and {@link ObjectReader},
* and when an actual instance is needed for deserialization,
* a fully configured instance will
* be created using a method in excented API of sub-class
* ({@link com.fasterxml.jackson.databind.deser.DefaultDeserializationContext#createInstance}).
* Each instance is guaranteed to only be used from single-threaded context;
* instances may be reused iff no configuration has changed.
*<p>
* Defined as abstract class so that implementations must define methods
* for reconfiguring blueprints and creating instances.
*/
public abstract class DeserializationContext
extends DatabindContext
implements java.io.Serializable
{
private static final long serialVersionUID = 1L; // 2.6
/**
* Let's limit length of error messages, for cases where underlying data
* may be very large -- no point in spamming logs with megs of meaningless
* data.
*/
private final static int MAX_ERROR_STR_LEN = 500;
/*
/**********************************************************
/* Configuration, immutable
/**********************************************************
*/
/**
* Object that handle details of {@link JsonDeserializer} caching.
*/
protected final DeserializerCache _cache;
/*
/**********************************************************
/* Configuration, changeable via fluent factories
/**********************************************************
*/
/**
* Read-only factory instance; exposed to let
* owners (<code>ObjectMapper</code>, <code>ObjectReader</code>)
* access it.
*/
protected final DeserializerFactory _factory;
/*
/**********************************************************
/* Configuration that
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.Arrays;
import java.util.UUID;
import com.fasterxml.jackson.core.Base64Variants;
import com.fasterxml.jackson.databind.DeserializationContext;
public class UUIDDeserializer extends FromStringDeserializer<UUID>
{
private static final long serialVersionUID = 1L;
final static int[] HEX_DIGITS = new int[127];
static {
Arrays.fill(HEX_DIGITS, -1);
for (int i = 0; i < 10; ++i) { HEX_DIGITS['0' + i] = i; }
for (int i = 0; i < 6; ++i) {
HEX_DIGITS['a' + i] = 10 + i;
HEX_DIGITS['A' + i] = 10 + i;
}
}
public UUIDDeserializer() { super(UUID.class); }
@Override
protected UUID _deserialize(String id, DeserializationContext ctxt) throws IOException
{
// Adapted from java-uuid-generator (https://github.com/cowtowncoder/java-uuid-generator)
// which is 5x faster than UUID.fromString(value), as oper "ManualReadPerfWithUUID"
if (id.length() != 36) {
/* 14-Sep-2013, tatu: One trick we do allow, Base64-encoding, since we know
* length it must have...
*/
if (id.length() == 24) {
byte[] stuff = Base64Variants.getDefaultVariant().decode(id);
return _fromBytes(stuff, ctxt);
}
_badFormat(id);
}
// verify hyphens first:
if ((id.charAt(8) != '-') || (id.charAt(13) != '-')
|| (id.charAt(18) != '-') || (id.charAt(23) != '-')) {
_badFormat(id);
}
long l1 = intFromChars(id, 0);
l1 <<= 32;
long l2 = ((long) shortFromChars(id, 9)) << 16;
l2 |= shortFromChars(id, 14);
long hi = l1 + l2;
int i1 = (shortFromChars(id, 19) << 16) | shortFromChars(id, 24);
l1 = i1;
l1 <<= 32;
l2 = intFromChars(id, 28);
l2 = (l2 << 32) >>> 32; // sign removal, Java-style. Ugh.
long lo = l1 | l2;
return new UUID(hi, lo);
}
@Override
protected UUID _deserializeEmbedded(Object ob, DeserializationContext ctxt) throws IOException
{
if
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeBindings;
import com.fasterxml.jackson.databind.type.TypeFactory;
/**
* Intermediate base class that encapsulates features that
* constructors and methods share.
*/
public abstract class AnnotatedWithParams
extends AnnotatedMember
{
private static final long serialVersionUID = 1L;
/**
* Annotations associated with parameters of the annotated
* entity (method or constructor parameters)
*/
protected final AnnotationMap[] _paramAnnotations;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
protected AnnotatedWithParams(AnnotatedClass ctxt, AnnotationMap annotations, AnnotationMap[] paramAnnotations)
{
super(ctxt, annotations);
_paramAnnotations = paramAnnotations;
}
/**
* Method called to override a method parameter annotation,
* usually due to a mix-in
* annotation masking or overriding an annotation 'real' method
* has.
*/
public final void addOrOverrideParam(int paramIndex, Annotation a)
{
AnnotationMap old = _paramAnnotations[paramIndex];
if (old == null) {
old = new AnnotationMap();
_paramAnnotations[paramIndex] = old;
}
old.add(a);
}
/**
* Method called by parameter object when an augmented instance is created;
* needs to replace parameter with new instance
*/
protected AnnotatedParameter replaceParameterAnnotations(int index, AnnotationMap ann)
{
_paramAnnotations[index] = ann;
return getParameter(index);
}
/*
/**********************************************************
/* Helper methods for subclasses
/**********************************************************
*/
protected JavaType getType(TypeBindings bindings, TypeVariable<?>[] typeParams)
{
// [JACKSON-468] Need to consider local type binding declarations too...
if (typeParams != null && typeParams.length > 0) {
bindings = bindings.childInstance();
for (TypeVariable<?> var : typeParams) {
String name = var.getName();
// to prevent infinite loops, need to first add placeholder ("<T extends Enum<T>>" etc)
bindings._addPlaceholder(name);
// About only useful piece of information is the lower bound (which is at least Object.class)
Type lowerBound = var.getBounds()[0];
JavaType type = (lowerBound == null) ? TypeFactory.unknownType()
: bindings.resolveType(lowerBound);
bindings.addBinding(var.getName(), type);
}
}
return bindings.resolveType(getGenericType());
}
/*
/**********************************************************
/* Partial Annotated impl
/**********************************************************
*/
@Override
public final <A extends Annotation> A getAnnotation(Class<A> acls) {
return _annotations.get(acls);
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser;
import java.util.*;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.SerializerFactoryConfig;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.impl.FilteredBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.impl.ObjectIdWriter;
import com.fasterxml.jackson.databind.ser.impl.PropertyBasedObjectIdGenerator;
import com.fasterxml.jackson.databind.ser.std.MapSerializer;
import com.fasterxml.jackson.databind.ser.std.StdDelegatingSerializer;
import com.fasterxml.jackson.databind.type.*;
import com.fasterxml.jackson.databind.util.ArrayBuilders;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.Converter;
/**
* Factory class that can provide serializers for any regular Java beans
* (as defined by "having at least one get method recognizable as bean
* accessor" -- where {@link Object#getClass} does not count);
* as well as for "standard" JDK types. Latter is achieved
* by delegating calls to {@link BasicSerializerFactory}
* to find serializers both for "standard" JDK types (and in some cases,
* sub-classes as is the case for collection classes like
* {@link java.util.List}s and {@link java.util.Map}s) and bean (value)
* classes.
*<p>
* Note about delegating calls to {@link BasicSerializerFactory}:
* although it would be nicer to use linear delegation
* for construction (to essentially dispatch all calls first to the
* underlying {@link BasicSerializerFactory}; or alternatively after
* failing to provide bean-based serializer}, there is a problem:
* priority levels for detecting standard types are mixed. That is,
* we want to check if a type is a bean after some of "standard" JDK
* types, but before the rest.
* As a result, "mixed" delegation used, and calls are NOT done using
* regular {@link SerializerFactory} interface but rather via
* direct calls to {@link BasicSerializerFactory}.
*<p>
* Finally, since all caching is handled by the serializer provider
* (not factory) and there is no configurability, this
* factory is stateless.
* This means that a global singleton instance can be used.
*/
public class BeanSerializerFactory
extends BasicSerializerFactory
implements java.io.Serializable // since 2.1
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>{
private static final long serialVersionUID = 1;
/**
* Like {@link BasicSerializerFactory}, this factory is stateless, and
* thus a single shared global (== singleton) instance can be used
* without thread-safety issues.
*/
public final static BeanSerializerFactory instance = new BeanSerializerFactory(null);
/*
/**********************************************************
/* Life-cycle: creation, configuration
/**********************************************************
*/
/**
* Constructor for creating instances with specified configuration.
*/
protected BeanSerializerFactory(SerializerFactoryConfig config)
{
super(config);
}
/**
* Method used by module registration functionality, to attach additional
* serializer providers into this serializer factory. This is typically
* handled by constructing a new instance with additional serializers,
* to ensure thread-safe access.
*/
@Override
public SerializerFactory withConfig(SerializerFactoryConfig config)
{
if (_factoryConfig == config) {
return this;
}
/* 22-Nov-2010, tatu: Handling of subtypes is tricky if we do immutable-with-copy-ctor;
* and we pretty much have to here either choose between losing subtype instance
* when registering additional serializers, or losing serializers.
* Instead, let's actually just throw an error if this method is called when subtype
* has not properly overridden this method; this to indicate problem as soon as possible.
*/
if (getClass() != BeanSerializerFactory.class) {
throw new IllegalStateException("Subtype of BeanSerializerFactory ("+getClass().getName()
+") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with "
+"additional serializer definitions");
}
return new BeanSerializerFactory(config);
}
@Override
protected Iterable<Serializers> customSerializers() {
return _factoryConfig.serializers();
}
/*
/**********************************************************
/* SerializerFactory impl
/**********************************************************
*/
/**
* Main serializer constructor method. We will have to be careful
* with respect to ordering of various method calls: essentially
* we want to reliably figure out which classes are standard types,
* and which are beans. The problem is that some bean Classes may
* implement standard interfaces (say, {@link java.lang.Iterable}.
*<p>
* Note: sub-classes may choose to complete replace implementation,
* if they want to alter priority of serializer lookups.
*/
@Override
@SuppressWarnings("unchecked")
public JsonSerializer<Object> createSerializer(SerializerProvider prov,
JavaType origType)
throws JsonMappingException
{
// Very first thing, let's check if there is explicit serializer annotation:
final SerializationConfig config = prov.getConfig();
BeanDescription beanDesc = config.introspect(origType);
JsonSerializer<?> ser = findSerializerFromAnnotation(prov, beanDesc.getClassInfo());
if (ser != null) {
return (JsonSerializer<Object>) ser;
}
boolean staticTyping;
// Next: we may have annotations that further define types to use...
JavaType type = modifyTypeByAnnotation(config,
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.cfg;
import java.text.DateFormat;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.Base64Variant;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.PropertyName;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.introspect.ClassIntrospector;
import com.fasterxml.jackson.databind.introspect.ClassIntrospector.MixInResolver;
import com.fasterxml.jackson.databind.introspect.SimpleMixInResolver;
import com.fasterxml.jackson.databind.introspect.VisibilityChecker;
import com.fasterxml.jackson.databind.jsontype.SubtypeResolver;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.RootNameLookup;
@SuppressWarnings("serial")
public abstract class MapperConfigBase<CFG extends ConfigFeature,
T extends MapperConfigBase<CFG,T>>
extends MapperConfig<T>
implements java.io.Serializable
{
private final static int DEFAULT_MAPPER_FEATURES = collectFeatureDefaults(MapperFeature.class);
/*
/**********************************************************
/* Immutable config
/**********************************************************
*/
/**
* Mix-in annotation mappings to use, if any: immutable,
* can not be changed once defined.
*
* @since 2.6
*/
protected final SimpleMixInResolver _mixIns;
/**
* Registered concrete subtypes that can be used instead of (or
* in addition to) ones declared using annotations.
*/
protected final SubtypeResolver _subtypeResolver;
/**
* Explicitly defined root name to use, if any; if empty
* String, will disable root-name wrapping; if null, will
* use defaults
*/
protected final PropertyName _rootName;
/**
* View to use for filtering out properties to serialize
* or deserialize.
* Null if none (will also be assigned null if <code>Object.class</code>
* is defined), meaning that all properties are to be included.
*/
protected final Class<?> _view;
/**
* Contextual attributes accessible (get and set) during processing,
* on per-call basis.
*
* @since 2.3
*/
protected final ContextAttributes _attributes;
/**
* @since 2.6
*/
protected final RootNameLookup _rootNames;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
/**
* Constructor used when creating a new instance (compared to
*
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.*;
import java.lang.reflect.Type;
import java.util.*;
import java.util.concurrent.atomic.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonIntegerFormatVisitor;
import com.fasterxml.jackson.databind.ser.BasicSerializerFactory;
/**
* Class that providers access to serializers user for non-structured JDK types that
* are serializer as scalars; some using basic {@link ToStringSerializer},
* others explicit serializers.
*/
@SuppressWarnings("serial")
public class StdJdkSerializers
{
/**
* Method called by {@link BasicSerializerFactory} to access
* all serializers this class provides.
*/
public static Collection<Map.Entry<Class<?>, Object>> all()
{
HashMap<Class<?>,Object> sers = new HashMap<Class<?>,Object>();
// First things that 'toString()' can handle
final ToStringSerializer sls = ToStringSerializer.instance;
sers.put(java.net.URL.class, sls);
sers.put(java.net.URI.class, sls);
sers.put(Currency.class, sls);
sers.put(UUID.class, new UUIDSerializer());
sers.put(java.util.regex.Pattern.class, sls);
sers.put(Locale.class, sls);
sers.put(Locale.class, sls);
// then atomic types (note: AtomicReference needs better handling)
sers.put(AtomicBoolean.class, AtomicBooleanSerializer.class);
sers.put(AtomicInteger.class, AtomicIntegerSerializer.class);
sers.put(AtomicLong.class, AtomicLongSerializer.class);
// then other types that need specialized serializers
sers.put(File.class, FileSerializer.class);
sers.put(Class.class, ClassSerializer.class);
// And then some stranger types... not 100% they are needed but:
sers.put(Void.class, NullSerializer.instance);
sers.put(Void.TYPE, NullSerializer.instance);
return sers.entrySet();
}
/*
/**********************************************************
/* Serializers for atomic types
/**********************************************************
*/
public static class AtomicBooleanSerializer
extends StdScalarSerializer<AtomicBoolean>
{
public AtomicBooleanSerializer() { super(AtomicBoolean.class, false); }
@Override
public void serialize(AtomicBoolean value, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonGenerationException {
gen.writeBoolean(value.get());
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("boolean", true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, Java
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.util.HashSet;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Variant of {@link BeanDeserializer} used for handling deserialization
* of POJOs when serialized as JSON Arrays, instead of JSON Objects.
*
* @since 2.1
*/
public class BeanAsArrayDeserializer
extends BeanDeserializerBase
{
private static final long serialVersionUID = 1L;
/**
* Deserializer we delegate operations that we can not handle.
*/
protected final BeanDeserializerBase _delegate;
/**
* Properties in order expected to be found in JSON array.
*/
protected final SettableBeanProperty[] _orderedProperties;
/*
/**********************************************************
/* Life-cycle, construction, initialization
/**********************************************************
*/
/**
* Main constructor used both for creating new instances (by
* {@link BeanDeserializer#asArrayDeserializer}) and for
* creating copies with different delegate.
*/
public BeanAsArrayDeserializer(BeanDeserializerBase delegate,
SettableBeanProperty[] ordered)
{
super(delegate);
_delegate = delegate;
_orderedProperties = ordered;
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper)
{
/* We can't do much about this; could either replace _delegate
* with unwrapping instance, or just replace this one. Latter seems
* more sensible.
*/
return _delegate.unwrappingDeserializer(unwrapper);
}
@Override
public BeanAsArrayDeserializer withObjectIdReader(ObjectIdReader oir) {
return new BeanAsArrayDeserializer(_delegate.withObjectIdReader(oir),
_orderedProperties);
}
@Override
public BeanAsArrayDeserializer withIgnorableProperties(HashSet<String> ignorableProps) {
return new BeanAsArrayDeserializer(_delegate.withIgnorableProperties(ignorableProps),
_orderedProperties);
}
@Override
protected BeanDeserializerBase asArrayDeserializer() {
return this;
}
/*
/**********************************************************
/* JsonDeserializer implementation
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException
{
// Let's delegate just in case we got a JSON Object (could error out, alternatively?)
if (!p.isExpectedStartArrayToken()) {
return _deserializeFromNonArray(p, ctxt);
}
if (!_vanillaProcessing) {
return _deserializeNonVanilla(p, ctxt);
}
final Object bean = _valueInstantiator.createUsingDefault(ctxt);
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
final SettableBeanProperty[] props = _orderedProperties;
int i =
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.*;
/**
* Dummy, "no-operation" implementation of {@link AnnotationIntrospector}.
* Can be used as is to suppress handling of annotations; or as a basis
* for simple configuration overrides (whether based on annotations or not).
*/
public abstract class NopAnnotationIntrospector
extends AnnotationIntrospector
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Static immutable and shareable instance that can be used as
* "null" introspector: one that never finds any annotation
* information.
*/
public final static NopAnnotationIntrospector instance = new NopAnnotationIntrospector() {
private static final long serialVersionUID = 1L;
@Override
public Version version() {
return com.fasterxml.jackson.databind.cfg.PackageVersion.VERSION;
}
};
@Override
public Version version() {
return Version.unknownVersion();
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import java.text.DateFormat;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
/**
* Compared to regular {@link java.util.Date} serialization, we do use String
* representation here. Why? Basically to truncate of time part, since
* that should not be used by plain SQL date.
*/
@JacksonStdImpl
@SuppressWarnings("serial")
public class SqlDateSerializer
extends DateTimeSerializerBase<java.sql.Date>
{
public SqlDateSerializer() {
/* 12-Apr-2014, tatu: for now, pass explicit 'false' to mean 'not using timestamp',
* for backwards compatibility; this differs from other Date/Calendar types.
*/
this(Boolean.FALSE);
}
protected SqlDateSerializer(Boolean useTimestamp) {
super(java.sql.Date.class, useTimestamp, null);
}
@Override
public SqlDateSerializer withFormat(Boolean timestamp, DateFormat customFormat) {
return new SqlDateSerializer(timestamp);
}
@Override
protected long _timestamp(java.sql.Date value) {
return (value == null) ? 0L : value.getTime();
}
@Override
public void serialize(java.sql.Date value, JsonGenerator gen, SerializerProvider provider)
throws IOException, JsonGenerationException
{
if (_asTimestamp(provider)) {
gen.writeNumber(_timestamp(value));
} else {
gen.writeString(value.toString());
}
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
//todo: (ryan) add a format for the date in the schema?
return createSchemaNode("string", true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
{
_acceptJsonFormatVisitor(visitor, typeHint, _useTimestamp);
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser;
import java.lang.reflect.Type;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.util.Annotations;
/**
* {@link BeanPropertyWriter} implementation used with
* {@link com.fasterxml.jackson.databind.annotation.JsonAppend}
* to add "virtual" properties in addition to regular ones.
*
* @since 2.5
*
* @see com.fasterxml.jackson.databind.ser.impl.AttributePropertyWriter
*/
public abstract class VirtualBeanPropertyWriter
extends BeanPropertyWriter
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Constructor used by most sub-types.
*/
protected VirtualBeanPropertyWriter(BeanPropertyDefinition propDef,
Annotations contextAnnotations, JavaType declaredType)
{
this(propDef, contextAnnotations, declaredType, null, null, null,
propDef.findInclusion());
}
/**
* Constructor that may be used by sub-classes for constructing a "blue-print" instance;
* one that will only become (or create) actual usable instance when its
* {@link #withConfig} method is called.
*/
protected VirtualBeanPropertyWriter() {
super();
}
/**
* Pass-through constructor that may be used by sub-classes that
* want full control over implementation.
*/
protected VirtualBeanPropertyWriter(BeanPropertyDefinition propDef,
Annotations contextAnnotations, JavaType declaredType,
JsonSerializer<?> ser, TypeSerializer typeSer, JavaType serType,
JsonInclude.Include inclusion)
{
super(propDef, propDef.getPrimaryMember(), contextAnnotations, declaredType,
ser, typeSer, serType,
_suppressNulls(inclusion), _suppressableValue(inclusion));
}
protected VirtualBeanPropertyWriter(VirtualBeanPropertyWriter base) {
super(base);
}
protected VirtualBeanPropertyWriter(VirtualBeanPropertyWriter base, PropertyName name) {
super(base, name);
}
protected static boolean _suppressNulls(JsonInclude.Include inclusion) {
return (inclusion != JsonInclude.Include.ALWAYS);
}
protected static Object _suppressableValue(JsonInclude.Include inclusion) {
if ((inclusion == JsonInclude.Include.NON_EMPTY)
|| (inclusion == JsonInclude.Include.NON_EMPTY)) {
return MARKER_FOR_EMPTY;
}
return null;
}
/*
/**********************************************************
/* Standard accessor overrides
/**********************************************************
*/
@Override
public boolean isVirtual() { return true; }
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Specialized POJO serializer that differs from
* {@link com.fasterxml.jackson.databind.ser.BeanSerializer}
* in that instead of producing a JSON Object it will output
* a JSON Array, omitting field names, and serializing values in
* specified serialization order.
* This behavior is usually triggered by using annotation
* {@link com.fasterxml.jackson.annotation.JsonFormat} or its
* equivalents.
*<p>
* This serializer can be used for "simple" instances; and will NOT
* be used if one of following is true:
*<ul>
* <li>Unwrapping is used (no way to expand out array in JSON Object)
* </li>
* <li>Type information ("type id") is to be used: while this could work
* for some embedding methods, it would likely cause conflicts.
* </li>
* <li>Object Identity ("object id") is used: while references would work,
* the problem is inclusion of id itself.
* </li>
*</ul>
* Note that it is theoretically possible that last 2 issues could be addressed
* (by reserving room in array, for example); and if so, support improved.
*<p>
* In cases where array-based output is not feasible, this serializer
* can instead delegate to the original Object-based serializer; this
* is why a reference is retained to the original serializer.
*
* @since 2.1
*/
public class BeanAsArraySerializer
extends BeanSerializerBase
{
private static final long serialVersionUID = 1L; // since 2.6
/**
* Serializer that would produce JSON Object version; used in
* cases where array output can not be used.
*/
protected final BeanSerializerBase _defaultSerializer;
/*
/**********************************************************
/* Life-cycle: constructors
/**********************************************************
*/
public BeanAsArraySerializer(BeanSerializerBase src) {
super(src, (ObjectIdWriter) null);
_defaultSerializer = src;
}
protected BeanAsArraySerializer(BeanSerializerBase src, String[] toIgnore) {
super(src, toIgnore);
_defaultSerializer = src;
}
protected BeanAsArraySerializer(BeanSerializerBase src,
ObjectIdWriter oiw, Object filterId) {
super(src, oiw, filterId);
_defaultSerializer = src;
}
/*
/**********************************************************
/* Life-cycle: factory methods, fluent factories
/**********************************************************
*/
@Override
public
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.jsontype;
/**
* Simple container class for types with optional logical name, used
* as external identifier
*/
public final class NamedType implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected final Class<?> _class;
protected final int _hashCode;
protected String _name;
public NamedType(Class<?> c) { this(c, null); }
public NamedType(Class<?> c, String name) {
_class = c;
_hashCode = c.getName().hashCode();
setName(name);
}
public Class<?> getType() { return _class; }
public String getName() { return _name; }
public void setName(String name) { _name = (name == null || name.length() == 0) ? null : name; }
public boolean hasName() { return _name != null; }
/**
* Equality is defined based on class only, not on name
*/
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
return _class == ((NamedType) o)._class;
}
@Override
public int hashCode() { return _hashCode; }
@Override
public String toString() {
return "[NamedType, class "+_class.getName()+", name: "+(_name == null ? "null" :("'"+_name+"'"))+"]";
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import java.util.*;
/**
* Abstract class that defines API for objects that provide value to
* "inject" during deserialization. An instance of this object
*/
public abstract class InjectableValues
{
/**
* Method called to find value identified by id <code>valueId</code> to
* inject as value of specified property during deserialization, passing
* POJO instance in which value will be injected if it is available
* (will be available when injected via field or setter; not available
* when injected via constructor or factory method argument).
*
* @param valueId Object that identifies value to inject; may be a simple
* name or more complex identifier object, whatever provider needs
* @param ctxt Deserialization context
* @param forProperty Bean property in which value is to be injected
* @param beanInstance Bean instance that contains property to inject,
* if available; null if bean has not yet been constructed.
*/
public abstract Object findInjectableValue(Object valueId, DeserializationContext ctxt,
BeanProperty forProperty, Object beanInstance);
/*
/**********************************************************
/* Standard implementation
/**********************************************************
*/
/**
* Simple standard implementation which uses a simple Map to
* store values to inject, identified by simple String keys.
*/
public static class Std
extends InjectableValues
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected final Map<String,Object> _values;
public Std() {
this(new HashMap<String,Object>());
}
public Std(Map<String,Object> values) {
_values = values;
}
public Std addValue(String key, Object value) {
_values.put(key, value);
return this;
}
public Std addValue(Class<?> classKey, Object value) {
_values.put(classKey.getName(), value);
return this;
}
@Override
public Object findInjectableValue(Object valueId, DeserializationContext ctxt,
BeanProperty forProperty, Object beanInstance)
{
if (!(valueId instanceof String)) {
String type = (valueId == null) ? "[null]" : valueId.getClass().getName();
throw new IllegalArgumentException("Unrecognized inject value id type ("+type+"), expecting String");
}
String key = (String) valueId;
Object ob = _values.get(key);
if (ob == null && !_values.containsKey(key)) {
throw new IllegalArgumentException("No injectable id with value '"+key+"' found (for property '"+forProperty.getName()+"')");
}
return ob;
}
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
import java.util.Calendar;
import java.util.Currency;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.io.NumberInput;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.EnumResolver;
/**
* Default {@link KeyDeserializer} implementation used for most {@link java.util.Map}
* types Jackson supports.
* Implemented as "chameleon" (or swiss pocket knife) class; not particularly elegant,
* but helps reduce number of classes and jar size (class metadata adds significant
* per-class overhead; much more than bytecode).
*/
@JacksonStdImpl
public class StdKeyDeserializer extends KeyDeserializer
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
public final static int TYPE_BOOLEAN = 1;
public final static int TYPE_BYTE = 2;
public final static int TYPE_SHORT = 3;
public final static int TYPE_CHAR = 4;
public final static int TYPE_INT = 5;
public final static int TYPE_LONG = 6;
public final static int TYPE_FLOAT = 7;
public final static int TYPE_DOUBLE = 8;
public final static int TYPE_LOCALE = 9;
public final static int TYPE_DATE = 10;
public final static int TYPE_CALENDAR = 11;
public final static int TYPE_UUID = 12;
public final static int TYPE_URI = 13;
public final static int TYPE_URL = 14;
public final static int TYPE_CLASS = 15;
public final static int TYPE_CURRENCY = 16;
final protected int _kind;
final protected Class<?> _keyClass;
/**
* Some types that are deserialized using a helper deserializer.
*/
protected final FromStringDeserializer<?> _deser;
protected StdKeyDeserializer(int kind, Class<?> cls) {
this(kind, cls, null);
}
protected StdKeyDeserializer(int kind, Class<?> cls, FromStringDeserializer<?> deser) {
_kind = kind;
_keyClass = cls;
_deser = deser;
}
public static StdKeyDeserializer forType(Class<?> raw)
{
int kind;
// first common types:
if (raw == String.class || raw == Object.
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>true' or 'false'");
case TYPE_BYTE:
{
int value = _parseInt(key);
// as per [JACKSON-804], allow range up to 255, inclusive
if (value < Byte.MIN_VALUE || value > 255) {
throw ctxt.weirdKeyException(_keyClass, key, "overflow, value can not be represented as 8-bit value");
}
return Byte.valueOf((byte) value);
}
case TYPE_SHORT:
{
int value = _parseInt(key);
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
throw ctxt.weirdKeyException(_keyClass, key, "overflow, value can not be represented as 16-bit value");
}
return Short.valueOf((short) value);
}
case TYPE_CHAR:
if (key.length() == 1) {
return Character.valueOf(key.charAt(0));
}
throw ctxt.weirdKeyException(_keyClass, key, "can only convert 1-character Strings");
case TYPE_INT:
return _parseInt(key);
case TYPE_LONG:
return _parseLong(key);
case TYPE_FLOAT:
// Bounds/range checks would be tricky here, so let's not bother even trying...
return Float.valueOf((float) _parseDouble(key));
case TYPE_DOUBLE:
return _parseDouble(key);
case TYPE_LOCALE:
try {
return _deser._deserialize(key, ctxt);
} catch (IOException e) {
throw ctxt.weirdKeyException(_keyClass, key, "unable to parse key as locale");
}
case TYPE_CURRENCY:
try {
return _deser._deserialize(key, ctxt);
} catch (IOException e) {
throw ctxt.weirdKeyException(_keyClass, key, "unable to parse key as currency");
}
case TYPE_DATE:
return ctxt.parseDate(key);
case TYPE_CALENDAR:
java.util.Date date = ctxt.parseDate(key);
return (date == null) ? null : ctxt.constructCalendar(date);
case TYPE_UUID:
return UUID.fromString(key);
case TYPE_URI:
return URI.create(key);
case TYPE_URL:
return new URL(key);
case TYPE_CLASS:
try {
return ctxt.findClass(key);
} catch (Exception e) {
throw ctxt.weirdKeyException(_keyClass, key, "unable to parse key as Class");
}
}
return null;
}
/*
/**********************************************************
/* Helper methods for sub-classes
/**********************************************************
*/
protected int _parseInt(String key) throws IllegalArgumentException {
return Integer.parseInt(key);
}
protected long _parseLong(String key) throws IllegalArgumentException {
return Long.parseLong(key);
}
protected double _parseDouble(String key) throws IllegalArgumentException {
return NumberInput.parseDouble(
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>key);
}
/*
/**********************************************************
/* First: the standard "String as String" deserializer
/**********************************************************
*/
@JacksonStdImpl
final static class StringKD extends StdKeyDeserializer
{
private static final long serialVersionUID = 1L;
private final static StringKD sString = new StringKD(String.class);
private final static StringKD sObject = new StringKD(Object.class);
private StringKD(Class<?> nominalType) { super(-1, nominalType); }
public static StringKD forType(Class<?> nominalType)
{
if (nominalType == String.class) {
return sString;
}
if (nominalType == Object.class) {
return sObject;
}
return new StringKD(nominalType);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt) throws IOException, JsonProcessingException {
return key;
}
}
/*
/**********************************************************
/* Key deserializer implementations; other
/**********************************************************
*/
/**
* Key deserializer that wraps a "regular" deserializer (but one
* that must recognize FIELD_NAMEs as text!) to reuse existing
* handlers as key handlers.
*/
final static class DelegatingKD
extends KeyDeserializer // note: NOT the std one
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
final protected Class<?> _keyClass;
protected final JsonDeserializer<?> _delegate;
protected DelegatingKD(Class<?> cls, JsonDeserializer<?> deser) {
_keyClass = cls;
_delegate = deser;
}
@Override
public final Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
if (key == null) { // is this even legal call?
return null;
}
try {
// Ugh... should not have to give parser which may or may not be correct one...
Object result = _delegate.deserialize(ctxt.getParser(), ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
throw ctxt.weirdKeyException(_keyClass, key, "not a valid representation: "+re.getMessage());
}
throw ctxt.weirdKeyException(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
}
@JacksonStdImpl
final static class EnumKD extends StdKeyDeserializer
{
private static final long serialVersionUID = 1L;
protected final EnumResolver _resolver;
protected final AnnotatedMethod _factory;
protected EnumKD(EnumResolver er, AnnotatedMethod factory) {
super(-1, er.getEnumClass());
_resolver = er;
_factory = factory;
}
@Override
public Object _parse(String key, DeserializationContext ctxt) throws JsonMappingException
{
if (_factory != null) {
try {
return _factory.call1(key);
} catch (Exception e) {
ClassUtil.unwrapAnd
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>ThrowAsIAE(e);
}
}
Enum<?> e = _resolver.findEnum(key);
if (e == null && !ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
throw ctxt.weirdKeyException(_keyClass, key, "not one of values for Enum class");
}
return e;
}
}
/**
* Key deserializer that calls a single-string-arg constructor
* to instantiate desired key type.
*/
final static class StringCtorKeyDeserializer extends StdKeyDeserializer
{
private static final long serialVersionUID = 1L;
protected final Constructor<?> _ctor;
public StringCtorKeyDeserializer(Constructor<?> ctor) {
super(-1, ctor.getDeclaringClass());
_ctor = ctor;
}
@Override
public Object _parse(String key, DeserializationContext ctxt) throws Exception
{
return _ctor.newInstance(key);
}
}
/**
* Key deserializer that calls a static no-args factory method
* to instantiate desired key type.
*/
final static class StringFactoryKeyDeserializer extends StdKeyDeserializer
{
private static final long serialVersionUID = 1L;
final Method _factoryMethod;
public StringFactoryKeyDeserializer(Method fm) {
super(-1, fm.getDeclaringClass());
_factoryMethod = fm;
}
@Override
public Object _parse(String key, DeserializationContext ctxt) throws Exception
{
return _factoryMethod.invoke(null, key);
}
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
import com.fasterxml.jackson.core.*;
/**
* Checked exception used to signal fatal problems with mapping of
* content.
*<p>
* One additional feature is the ability to denote relevant path
* of references (during serialization/deserialization) to help in
* troubleshooting.
*/
public class JsonMappingException
extends JsonProcessingException
{
private static final long serialVersionUID = 1L;
/**
* Let's limit length of reference chain, to limit damage in cases
* of infinite recursion.
*/
final static int MAX_REFS_TO_LIST = 1000;
/*
/**********************************************************
/* Helper classes
/**********************************************************
*/
/**
* Simple bean class used to contain references. References
* can be added to indicate execution/reference path that
* lead to the problem that caused this exception to be
* thrown.
*/
public static class Reference implements Serializable
{
private static final long serialVersionUID = 1L;
/**
* Object through which reference was resolved. Can be either
* actual instance (usually the case for serialization), or
* Class (usually the case for deserialization).
*/
protected Object _from;
/**
* Name of field (for beans) or key (for Maps) that is part
* of the reference. May be null for Collection types (which
* generally have {@link #_index} defined), or when resolving
* Map classes without (yet) having an instance to operate on.
*/
protected String _fieldName;
/**
* Index within a {@link Collection} instance that contained
* the reference; used if index is relevant and available.
* If either not applicable, or not available, -1 is used to
* denote "not known".
*/
protected int _index = -1;
/**
* Default constructor for deserialization/sub-classing purposes
*/
protected Reference() { }
public Reference(Object from) { _from = from; }
public Reference(Object from, String fieldName) {
_from = from;
if (fieldName == null) {
throw new NullPointerException("Can not pass null fieldName");
}
_fieldName = fieldName;
}
public Reference(Object from, int index) {
_from = from;
_index = index;
}
public void setFrom(Object o) { _from = o; }
public void setFieldName(String n) { _fieldName = n; }
public void setIndex(int ix) { _index = ix; }
public Object getFrom() { return _from; }
public String getFieldName() { return _fieldName; }
public int getIndex() { return _index; }
@Override public String toString() {
StringBuilder sb = new StringBuilder();
Class<?> cls = (_from instanceof Class<?>) ?
((Class<?>)_from) : _from.getClass();
/* Hmmh. Although Class.getName() is mostly ok,
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.ContainerSerializer;
import com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase;
/**
* This is an optimized serializer for Lists that can be efficiently
* traversed by index (as opposed to others, such as {@link LinkedList}
* that can not}.
*/
@JacksonStdImpl
public final class IndexedListSerializer
extends AsArraySerializerBase<List<?>>
{
private static final long serialVersionUID = 1L;
public IndexedListSerializer(JavaType elemType, boolean staticTyping, TypeSerializer vts,
JsonSerializer<Object> valueSerializer)
{
super(List.class, elemType, staticTyping, vts, valueSerializer);
}
public IndexedListSerializer(IndexedListSerializer src,
BeanProperty property, TypeSerializer vts, JsonSerializer<?> valueSerializer,
Boolean unwrapSingle) {
super(src, property, vts, valueSerializer, unwrapSingle);
}
@Override
public IndexedListSerializer withResolved(BeanProperty property,
TypeSerializer vts, JsonSerializer<?> elementSerializer,
Boolean unwrapSingle) {
return new IndexedListSerializer(this, property, vts, elementSerializer, unwrapSingle);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public boolean isEmpty(SerializerProvider prov, List<?> value) {
return (value == null) || value.isEmpty();
}
@Override
public boolean hasSingleElement(List<?> value) {
return (value.size() == 1);
}
@Override
public ContainerSerializer<?> _withValueTypeSerializer(TypeSerializer vts) {
return new IndexedListSerializer(this,
_property, vts, _elementSerializer, _unwrapSingle);
}
@Override
public final void serialize(List<?> value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
final int len = value.size();
if (len == 1) {
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
serializeContents(value, gen, provider);
gen.writeEndArray();
}
@Override
public void serializeContents(List<?> value, JsonGenerator jgen, SerializerProvider provider)
throws IOException
{
if (_elementSerializer != null) {
serializeContentsUsing(value, jgen, provider, _elementSerializer);
return;
}
if (_valueTypeSerializer != null) {
serializeTypedContents(value
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import java.text.DateFormat;
import java.util.*;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.cfg.*;
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.*;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.LinkedNode;
import com.fasterxml.jackson.databind.util.RootNameLookup;
/**
* Object that contains baseline configuration for deserialization
* process. An instance is owned by {@link ObjectMapper}, which
* passes an immutable instance to be used for deserialization process.
*<p>
* Note that instances are considered immutable and as such no copies
* should need to be created for sharing; all copying is done with
* "fluent factory" methods.
*/
public final class DeserializationConfig
extends MapperConfigBase<DeserializationFeature, DeserializationConfig>
implements java.io.Serializable // since 2.1
{
// since 2.5
private static final long serialVersionUID = 1;
/**
* Set of {@link DeserializationFeature}s enabled.
*/
protected final int _deserFeatures;
/**
* Linked list that contains all registered problem handlers.
* Implementation as front-added linked list allows for sharing
* of the list (tail) without copying the list.
*/
protected final LinkedNode<DeserializationProblemHandler> _problemHandlers;
/**
* Factory used for constructing {@link com.fasterxml.jackson.databind.JsonNode} instances.
*/
protected final JsonNodeFactory _nodeFactory;
/**
* States of {@link com.fasterxml.jackson.core.JsonParser.Feature}s to enable/disable.
*/
protected final int _parserFeatures;
/**
* Bitflag of {@link com.fasterxml.jackson.core.JsonParser.Feature}s to enable/disable
*/
protected final int _parserFeaturesToChange;
/*
/**********************************************************
/* Life-cycle, constructors
/**********************************************************
*/
/**
* Constructor used by ObjectMapper to create default configuration object instance.
*/
public DeserializationConfig(BaseSettings base,
SubtypeResolver str, SimpleMixInResolver mixins,
RootNameLookup rootNames)
{
super(base, str, mixins, rootNames);
_deserFeatures = collectFeatureDefaults(DeserializationFeature.class);
_nodeFactory = JsonNodeFactory.instance;
_problemHandlers = null;
_parserFeatures = 0;
_parserFeaturesToChange = 0;
}
private DeserializationConfig(DeserializationConfig src,
int mapperFeatures, int deserFeatures,
int parserFeatures,
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Member;
import java.lang.reflect.Type;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
/**
* Object that represents method parameters, mostly so that associated
* annotations can be processed conveniently. Note that many of accessors
* can not return meaningful values since parameters do not have stand-alone
* JDK objects associated; so access should mostly be limited to checking
* annotation values which are properly aggregated and included.
*/
public final class AnnotatedParameter
extends AnnotatedMember
{
private static final long serialVersionUID = 1L;
/**
* Member (method, constructor) that this parameter belongs to
*/
protected final AnnotatedWithParams _owner;
/**
* JDK type of the parameter, possibly contains generic type information
*/
protected final Type _type;
/**
* Index of the parameter within argument list
*/
protected final int _index;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public AnnotatedParameter(AnnotatedWithParams owner, Type type, AnnotationMap annotations,
int index)
{
super((owner == null) ? null : owner.getContextClass(), annotations);
_owner = owner;
_type = type;
_index = index;
}
@Override
public AnnotatedParameter withAnnotations(AnnotationMap ann) {
if (ann == _annotations) {
return this;
}
return _owner.replaceParameterAnnotations(_index, ann);
}
/*
/**********************************************************
/* Annotated impl
/**********************************************************
*/
/**
* Since there is no matching JDK element, this method will
* always return null
*/
@Override
public AnnotatedElement getAnnotated() { return null; }
/**
* Returns modifiers of the constructor, as parameters do not
* have independent modifiers.
*/
@Override
public int getModifiers() { return _owner.getModifiers(); }
/**
* Parameters have no names in bytecode (unlike in source code),
* will always return empty String ("").
*/
@Override
public String getName() { return ""; }
/**
* Accessor for annotations; all annotations associated with parameters
* are properly passed and accessible.
*/
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls)
{
return (_annotations == null) ? null : _annotations.get(acls);
}
@Override
public Type getGenericType() {
return _type;
}
@Override
public Class<?> getRawType()
{
if (_type instanceof Class<?>) {
return (Class<?>) _type;
}
// 14-Mar-2011, tatu: Not optimal, but has to do for now...
JavaType t = TypeFactory.defaultInstance().constructType(_type);
return t.getRaw
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonschema.SchemaAware;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.PropertyFilter;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.Converter;
/**
* Base class used by all standard serializers, and can also
* be used for custom serializers (in fact, this is the recommended
* base class to use).
* Provides convenience methods for implementing {@link SchemaAware}
*/
public abstract class StdSerializer<T>
extends JsonSerializer<T>
implements JsonFormatVisitable, SchemaAware, java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Nominal type supported, usually declared type of
* property for which serializer is used.
*/
protected final Class<T> _handledType;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
protected StdSerializer(Class<T> t) {
_handledType = t;
}
@SuppressWarnings("unchecked")
protected StdSerializer(JavaType type) {
_handledType = (Class<T>) type.getRawClass();
}
/**
* Alternate constructor that is (alas!) needed to work
* around kinks of generic type handling
*/
@SuppressWarnings("unchecked")
protected StdSerializer(Class<?> t, boolean dummy) {
_handledType = (Class<T>) t;
}
/**
* @since 2.6
*/
@SuppressWarnings("unchecked")
protected StdSerializer(StdSerializer<?> src) {
_handledType = (Class<T>) src._handledType;
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public Class<T> handledType() { return _handledType; }
/*
/**********************************************************
/* Serialization
/**********************************************************
*/
@Override
public abstract void serialize(T value, JsonGenerator gen, SerializerProvider provider)
throws IOException;
/*
/**********************************************************
/* Helper methods for JSON Schema generation
/**********************************************************
*/
/**
* Default implementation simply claims type is "string"; usually
* overriden by custom serializers.
*/
@Override
public JsonNode get
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.deser.UnresolvedForwardReference;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring;
import com.fasterxml.jackson.databind.deser.std.ContainerDeserializerBase;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
/**
* Basic serializer that can take JSON "Array" structure and
* construct a {@link java.util.Collection} instance, with typed contents.
*<p>
* Note: for untyped content (one indicated by passing Object.class
* as the type), {@link UntypedObjectDeserializer} is used instead.
* It can also construct {@link java.util.List}s, but not with specific
* POJO types, only other containers and primitives/wrappers.
*/
@JacksonStdImpl
public class CollectionDeserializer
extends ContainerDeserializerBase<Collection<Object>>
implements ContextualDeserializer
{
private static final long serialVersionUID = -1L; // since 2.5
// // Configuration
protected final JavaType _collectionType;
/**
* Value deserializer.
*/
protected final JsonDeserializer<Object> _valueDeserializer;
/**
* If element instances have polymorphic type information, this
* is the type deserializer that can handle it
*/
protected final TypeDeserializer _valueTypeDeserializer;
// // Instance construction settings:
protected final ValueInstantiator _valueInstantiator;
/**
* Deserializer that is used iff delegate-based creator is
* to be used for deserializing from JSON Object.
*/
protected final JsonDeserializer<Object> _delegateDeserializer;
// NOTE: no PropertyBasedCreator, as JSON Arrays have no properties
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
/**
* Constructor for context-free instances, where we do not yet know
* which property is using this deserializer.
*/
public CollectionDeserializer(JavaType collectionType,
JsonDeserializer<Object> valueDeser,
TypeDeserializer valueTypeDeser, ValueInstantiator valueInstantiator)
{
this(collectionType, valueDeser, valueTypeDeser, valueInstantiator, null);
}
/**
* Constructor used when creating contextualized instances.
*/
protected CollectionDeserializer(JavaType collectionType,
JsonDeserializer<Object> valueDeser, TypeDeserializer valueTypeDeser,
ValueInstantiator valueInstantiator,
JsonDeserializer<Object> delegateDeser)
{
super(collectionType);
_collectionType = collectionType;
_valueDeserializer = valueDeser;
_valueTypeDeserializer = valueTypeDeser;
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Helper class used for storing mapping from property name to
* {@link SettableBeanProperty} instances.
*<p>
* Note that this class is used instead of generic {@link java.util.HashMap}
* for bit of performance gain (and some memory savings): although default
* implementation is very good for generic use cases, it can be streamlined
* a bit for specific use case we have. Even relatively small improvements
* matter since this is directly on the critical path during deserialization,
* as it is done for each and every POJO property deserialized.
*/
public class BeanPropertyMap
implements Iterable<SettableBeanProperty>,
java.io.Serializable
{
private static final long serialVersionUID = 2L;
/**
* @since 2.5
*/
protected final boolean _caseInsensitive;
private int _hashMask;
/**
* Number of entries stored in the hash area.
*/
private int _size;
private int _spillCount;
/**
* Hash area that contains key/property pairs in adjacent elements.
*/
private Object[] _hashArea;
/**
* Array of properties in the exact order they were handed in. This is
* used by as-array serialization, deserialization.
*/
private SettableBeanProperty[] _propsInOrder;
public BeanPropertyMap(boolean caseInsensitive, Collection<SettableBeanProperty> props)
{
_caseInsensitive = caseInsensitive;
_propsInOrder = props.toArray(new SettableBeanProperty[props.size()]);
init(props);
}
protected void init(Collection<SettableBeanProperty> props)
{
_size = props.size();
// First: calculate size of primary hash area
final int hashSize = findSize(_size);
_hashMask = hashSize-1;
// and allocate enough to contain primary/secondary, expand for spillovers as need be
int alloc = (hashSize + (hashSize>>1)) * 2;
Object[] hashed = new Object[alloc];
int spillCount = 0;
for (SettableBeanProperty prop : props) {
// Due to removal, renaming, theoretically possible we'll have "holes" so:
if (prop == null) {
continue;
}
String key = getPropertyName(prop);
int slot = _hashCode
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.DeserializerFactoryConfig;
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
import com.fasterxml.jackson.databind.deser.impl.CreatorCollector;
import com.fasterxml.jackson.databind.deser.std.*;
import com.fasterxml.jackson.databind.ext.OptionalHandlerFactory;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.type.*;
import com.fasterxml.jackson.databind.util.*;
/**
* Abstract factory base class that can provide deserializers for standard
* JDK classes, including collection classes and simple heuristics for
* "upcasting" common collection interface types
* (such as {@link java.util.Collection}).
*<p>
* Since all simple deserializers are eagerly instantiated, and there is
* no additional introspection or customizability of these types,
* this factory is stateless.
*/
@SuppressWarnings("serial")
public abstract class BasicDeserializerFactory
extends DeserializerFactory
implements java.io.Serializable
{
private final static Class<?> CLASS_OBJECT = Object.class;
private final static Class<?> CLASS_STRING = String.class;
private final static Class<?> CLASS_CHAR_BUFFER = CharSequence.class;
private final static Class<?> CLASS_ITERABLE = Iterable.class;
private final static Class<?> CLASS_MAP_ENTRY = Map.Entry.class;
/**
* We need a placeholder for creator properties that don't have name
* but are marked with `@JsonWrapped` annotation.
*/
protected final static PropertyName UNWRAPPED_CREATOR_PARAM_NAME = new PropertyName("@JsonUnwrapped");
/* We do some defaulting for abstract Map classes and
* interfaces, to avoid having to use exact types or annotations in
* cases where the most common concrete Maps will do.
*/
@SuppressWarnings("rawtypes")
final static HashMap<String, Class<? extends Map>> _mapFallbacks =
new HashMap<String, Class<? extends Map>>();
static {
_mapFallbacks.put(Map.class.getName(), LinkedHashMap.class);
_mapFallbacks.put(ConcurrentMap.class.getName(), ConcurrentHashMap.class);
_mapFallbacks.put(SortedMap.class.getName(), TreeMap.class);
_mapFallbacks.put(java.util.NavigableMap.class.getName(), TreeMap.class);
_
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>mapFallbacks.put(java.util.concurrent.ConcurrentNavigableMap.class.getName(),
java.util.concurrent.ConcurrentSkipListMap.class);
}
/* We do some defaulting for abstract Collection classes and
* interfaces, to avoid having to use exact types or annotations in
* cases where the most common concrete Collection will do.
*/
@SuppressWarnings("rawtypes")
final static HashMap<String, Class<? extends Collection>> _collectionFallbacks =
new HashMap<String, Class<? extends Collection>>();
static {
_collectionFallbacks.put(Collection.class.getName(), ArrayList.class);
_collectionFallbacks.put(List.class.getName(), ArrayList.class);
_collectionFallbacks.put(Set.class.getName(), HashSet.class);
_collectionFallbacks.put(SortedSet.class.getName(), TreeSet.class);
_collectionFallbacks.put(Queue.class.getName(), LinkedList.class);
// then 1.6 types:
/* 17-May-2013, tatu: [Issue#216] Should be fine to use straight Class references EXCEPT
* that some godforsaken platforms (... looking at you, Android) do not
* include these. So, use "soft" references...
*/
_collectionFallbacks.put("java.util.Deque", LinkedList.class);
_collectionFallbacks.put("java.util.NavigableSet", TreeSet.class);
}
/*
/**********************************************************
/* Config
/**********************************************************
*/
/**
* Configuration settings for this factory; immutable instance (just like this
* factory), new version created via copy-constructor (fluent-style)
*/
protected final DeserializerFactoryConfig _factoryConfig;
/*
/**********************************************************
/* Life cycle
/**********************************************************
*/
protected BasicDeserializerFactory(DeserializerFactoryConfig config) {
_factoryConfig = config;
}
/**
* Method for getting current {@link DeserializerFactoryConfig}.
*<p>
* Note that since instances are immutable, you can NOT change settings
* by accessing an instance and calling methods: this will simply create
* new instance of config object.
*/
public DeserializerFactoryConfig getFactoryConfig() {
return _factoryConfig;
}
protected abstract DeserializerFactory withConfig(DeserializerFactoryConfig config);
/*
/********************************************************
/* Configuration handling: fluent factories
/********************************************************
*/
/**
* Convenience method for creating a new factory instance with additional deserializer
* provider.
*/
@Override
public final DeserializerFactory withAdditionalDeserializers(Deserializers additional) {
return withConfig(_factoryConfig.withAdditionalDeserializers(additional));
}
/**
* Convenience method for creating a new factory instance with additional
* {@link KeyDeserializers}.
*/
@Override
public final DeserializerFactory withAdditionalKeyDeserializers(KeyDeserializers additional) {
return withConfig(_factoryConfig.withAdditionalKeyDeserializers(additional));
}
/**
* Convenience method for creating a new factory instance with additional
* {@link BeanDeserializerModifier}.
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.cfg;
import com.fasterxml.jackson.databind.AbstractTypeResolver;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.deser.std.StdKeyDeserializers;
import com.fasterxml.jackson.databind.util.ArrayBuilders;
import com.fasterxml.jackson.databind.util.ArrayIterator;
/**
* Configuration settings container class for {@link DeserializerFactory}.
*/
public class DeserializerFactoryConfig
implements java.io.Serializable // since 2.1
{
private static final long serialVersionUID = 1L; // since 2.5
protected final static Deserializers[] NO_DESERIALIZERS = new Deserializers[0];
protected final static BeanDeserializerModifier[] NO_MODIFIERS = new BeanDeserializerModifier[0];
protected final static AbstractTypeResolver[] NO_ABSTRACT_TYPE_RESOLVERS = new AbstractTypeResolver[0];
protected final static ValueInstantiators[] NO_VALUE_INSTANTIATORS = new ValueInstantiators[0];
/**
* By default we plug default key deserializers using as "just another" set of
* of key deserializers.
*
* @since 2.2
*/
protected final static KeyDeserializers[] DEFAULT_KEY_DESERIALIZERS = new KeyDeserializers[] {
new StdKeyDeserializers()
};
/**
* List of providers for additional deserializers, checked before considering default
* basic or bean deserializers.
*/
protected final Deserializers[] _additionalDeserializers;
/**
* List of providers for additional key deserializers, checked before considering
* standard key deserializers.
*/
protected final KeyDeserializers[] _additionalKeyDeserializers;
/**
* List of modifiers that can change the way {@link BeanDeserializer} instances
* are configured and constructed.
*/
protected final BeanDeserializerModifier[] _modifiers;
/**
* List of objects that may be able to resolve abstract types to
* concrete types. Used by functionality like "mr Bean" to materialize
* types as needed.
*/
protected final AbstractTypeResolver[] _abstractTypeResolvers;
/**
* List of objects that know how to create instances of POJO types;
* possibly using custom construction (non-annoted constructors; factory
* methods external to value type etc).
* Used to support objects that are created using non-standard methods;
* or to support post-constructor functionality.
*/
protected final ValueInstantiators[] _valueInstantiators;
/**
* Constructor for creating basic configuration with no additional
* handlers.
*/
public DeserializerFactoryConfig() {
this(null, null, null, null, null);
}
/**
* Copy-constructor that will create an instance that contains defined
* set of additional deserializer providers.
*/
protected DeserializerFactoryConfig(Deserializers[] allAdditionalDeserializers,
KeyDeserializers[] allAdditionalKeyDeserializers,
BeanDeserializerModifier[] modifiers,
AbstractTypeResolver[] atr,
ValueInstantiators[] vi)
{
_additionalDeserializers
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import java.io.Closeable;
import java.io.IOException;
import java.util.Collection;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.TypeWrappedSerializer;
/**
* Writer class similar to {@link ObjectWriter}, except that it can be used
* for writing sequences of values, not just a single value.
* The main use case is in writing very long sequences, or sequences where
* values are incrementally produced; cases where it would be impractical
* or at least inconvenient to construct a wrapper container around values
* (or where no JSON array is desired around values).
*<p>
* Differences from {@link ObjectWriter} include:
*<ul>
* <li>Instances of {@link SequenceWriter} are stateful, and not thread-safe:
* if sharing, external synchronization must be used.
* <li>Explicit {@link #close} is needed after all values have been written
* ({@link ObjectWriter} can auto-close after individual value writes)
*</ul>
*
* @since 2.5
*/
public class SequenceWriter
implements Versioned, java.io.Closeable, java.io.Flushable
{
/*
/**********************************************************
/* Configuration
/**********************************************************
*/
protected final DefaultSerializerProvider _provider;
protected final SerializationConfig _config;
protected final JsonGenerator _generator;
protected final JsonSerializer<Object> _rootSerializer;
protected final TypeSerializer _typeSerializer;
protected final boolean _closeGenerator;
protected final boolean _cfgFlush;
protected final boolean _cfgCloseCloseable;
/*
/**********************************************************
/* State
/**********************************************************
*/
/**
* If {@link #_rootSerializer} is not defined (no root type
* was used for constructing {@link ObjectWriter}), we will
* use simple scheme for keeping track of serializers needed.
* Assumption is that
*/
protected PropertySerializerMap _dynamicSerializers;
/**
* State flag for keeping track of need to write matching END_ARRAY,
* if a START_ARRAY was written during initialization
*/
protected boolean _openArray;
protected boolean _closed;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public SequenceWriter(DefaultSerializerProvider prov, JsonGenerator gen,
boolean closeGenerator, ObjectWriter.Prefetch prefetch)
throws IOException
{
_provider = prov;
_generator = gen;
_closeGenerator = closeGenerator;
_rootSerializer = prefetch.getValueSerializer();
_typeSerializer = prefetch.getTypeSerializer();
_config = prov.getConfig();
_cfgFlush = _config.isEnabled(SerializationFeature.FLUSH_AFTER_WRITE_VALUE);
_cfgCloseCloseable = _
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
/**
* This is the special serializer for regular {@link java.lang.String}s.
*<p>
* Since this is one of "native" types, no type information is ever
* included on serialization (unlike for most scalar types as of 1.5)
*/
@JacksonStdImpl
public final class StringSerializer
// NOTE: generic parameter changed from String to Object in 2.6, to avoid
// use of bridge methods
extends NonTypedScalarSerializerBase<Object>
{
private static final long serialVersionUID = 1L;
public StringSerializer() { super(String.class, false); }
/**
* For Strings, both null and Empty String qualify for emptiness.
*/
@Override
@Deprecated
public boolean isEmpty(Object value) {
String str = (String) value;
return (str == null) || (str.length() == 0);
}
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
String str = (String) value;
return (str == null) || (str.length() == 0);
}
@Override
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeString((String) value);
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("string", true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException {
if (visitor != null) visitor.expectStringFormat(typeHint);
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.lang.reflect.Array;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.type.ArrayType;
import com.fasterxml.jackson.databind.util.ObjectBuffer;
/**
* Basic serializer that can serialize non-primitive arrays.
*/
@JacksonStdImpl
public class ObjectArrayDeserializer
extends ContainerDeserializerBase<Object[]>
implements ContextualDeserializer
{
private static final long serialVersionUID = 1L;
// // Configuration
/**
* Full generic type of the array being deserialized
*/
protected final ArrayType _arrayType;
/**
* Flag that indicates whether the component type is Object or not.
* Used for minor optimization when constructing result.
*/
protected final boolean _untyped;
/**
* Type of contained elements: needed for constructing actual
* result array
*/
protected final Class<?> _elementClass;
/**
* Element deserializer
*/
protected JsonDeserializer<Object> _elementDeserializer;
/**
* If element instances have polymorphic type information, this
* is the type deserializer that can handle it
*/
protected final TypeDeserializer _elementTypeDeserializer;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public ObjectArrayDeserializer(ArrayType arrayType,
JsonDeserializer<Object> elemDeser, TypeDeserializer elemTypeDeser)
{
super(arrayType);
_arrayType = arrayType;
_elementClass = arrayType.getContentType().getRawClass();
_untyped = (_elementClass == Object.class);
_elementDeserializer = elemDeser;
_elementTypeDeserializer = elemTypeDeser;
}
/**
* Overridable fluent-factory method used to create contextual instances
*/
@SuppressWarnings("unchecked")
public ObjectArrayDeserializer withDeserializer(TypeDeserializer elemTypeDeser,
JsonDeserializer<?> elemDeser)
{
if ((elemDeser == _elementDeserializer) && (elemTypeDeser == _elementTypeDeserializer)) {
return this;
}
return new ObjectArrayDeserializer(_arrayType,
(JsonDeserializer<Object>) elemDeser, elemTypeDeser);
}
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
JsonDeserializer<?> deser = _elementDeserializer;
// #125: May have a content converter
deser = findConvertingContentDeserializer(ctxt, property, deser);
final JavaType vt = _arrayType.getContentType();
if (deser == null) {
deser = ctxt.findContextualValueDeserializer(vt, property);
} else { // if directly assigned, probably not yet contextual, so:
deser = ctxt.handle
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.ser.impl.BeanAsArraySerializer;
import com.fasterxml.jackson.databind.ser.impl.ObjectIdWriter;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanSerializer;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Serializer class that can serialize Java objects that map
* to JSON Object output. Internally handling is mostly dealt with
* by a sequence of {@link BeanPropertyWriter}s that will handle
* access value to serialize and call appropriate serializers to
* write out JSON.
*<p>
* Implementation note: we will post-process resulting serializer,
* to figure out actual serializers for final types. This must be
* done from {@link #resolve} method, and NOT from constructor;
* otherwise we could end up with an infinite loop.
*/
public class BeanSerializer
extends BeanSerializerBase
{
private static final long serialVersionUID = -3618164443537292758L;
/*
/**********************************************************
/* Life-cycle: constructors
/**********************************************************
*/
/**
* @param builder Builder object that contains collected information
* that may be needed for serializer
* @param properties Property writers used for actual serialization
*/
public BeanSerializer(JavaType type, BeanSerializerBuilder builder,
BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties)
{
super(type, builder, properties, filteredProperties);
}
/**
* Alternate copy constructor that can be used to construct
* standard {@link BeanSerializer} passing an instance of
* "compatible enough" source serializer.
*/
protected BeanSerializer(BeanSerializerBase src) {
super(src);
}
protected BeanSerializer(BeanSerializerBase src,
ObjectIdWriter objectIdWriter) {
super(src, objectIdWriter);
}
protected BeanSerializer(BeanSerializerBase src,
ObjectIdWriter objectIdWriter, Object filterId) {
super(src, objectIdWriter, filterId);
}
protected BeanSerializer(BeanSerializerBase src, String[] toIgnore) {
super(src, toIgnore);
}
/*
/**********************************************************
/* Life-cycle: factory methods, fluent factories
/**********************************************************
*/
/**
* Method for constructing dummy bean serializer; one that
* never outputs any properties
*/
public static BeanSerializer createDummy(JavaType forType)
{
return new BeanSerializer(forType, null, NO_PROPS, null);
}
@Override
public JsonSerializer<Object> unwrappingSerializer(NameTransformer unwrapper) {
return new UnwrappingBeanSerializer(this, unwrapper);
}
@Override
public BeanSerializerBase withObjectIdWriter(ObjectIdWriter objectIdWriter) {
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
/**
* Class that represents a "wildcard" set method which can be used
* to generically set values of otherwise unmapped (aka "unknown")
* properties read from Json content.
*<p>
* !!! Note: might make sense to refactor to share some code
* with {@link SettableBeanProperty}?
*/
public class SettableAnyProperty
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Method used for setting "any" properties, along with annotation
* information. Retained to allow contextualization of any properties.
*/
protected final BeanProperty _property;
/**
* Annotated variant is needed for JDK serialization only
*/
final protected AnnotatedMethod _setter;
protected final JavaType _type;
protected JsonDeserializer<Object> _valueDeserializer;
protected final TypeDeserializer _valueTypeDeserializer;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public SettableAnyProperty(BeanProperty property, AnnotatedMethod setter, JavaType type,
JsonDeserializer<Object> valueDeser, TypeDeserializer typeDeser)
{
_property = property;
_setter = setter;
_type = type;
_valueDeserializer = valueDeser;
_valueTypeDeserializer = typeDeser;
}
public SettableAnyProperty withValueDeserializer(JsonDeserializer<Object> deser) {
return new SettableAnyProperty(_property, _setter, _type,
deser, _valueTypeDeserializer);
}
/**
* Constructor used for JDK Serialization when reading persisted object
*/
protected SettableAnyProperty(SettableAnyProperty src)
{
_property = src._property;
_setter = src._setter;
_type = src._type;
_valueDeserializer = src._valueDeserializer;
_valueTypeDeserializer = src._valueTypeDeserializer;
}
/*
/**********************************************************
/* JDK serialization handling
/**********************************************************
*/
/**
* Need to define this to verify that we retain actual Method reference
*/
Object readResolve() {
// sanity check...
if (_setter == null || _setter.getAnnotated() == null) {
throw new IllegalArgumentException("Missing method (broken JDK (de)serialization?)");
}
return this;
}
/*
/**********************************************************
/* Public API, accessors
/**********************************************************
*/
public BeanProperty getProperty() { return _property; }
public boolean hasValueDeserializer() { return (_valueDeserializer != null); }
public JavaType getType() { return _type; }
/*
/**********************************************************
/* Public API, deserialization
/**********************************************************
*/
/**
* Method called to deserialize appropriate value
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.BeanProperty;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.ContainerSerializer;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
/**
* Fallback serializer for cases where Collection is not known to be
* of type for which more specializer serializer exists (such as
* index-accessible List).
* If so, we will just construct an {@link java.util.Iterator}
* to iterate over elements.
*/
public class CollectionSerializer
extends AsArraySerializerBase<Collection<?>>
{
private static final long serialVersionUID = 1L;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
/**
* @since 2.6
*/
public CollectionSerializer(JavaType elemType, boolean staticTyping, TypeSerializer vts,
JsonSerializer<Object> valueSerializer) {
super(Collection.class, elemType, staticTyping, vts, valueSerializer);
}
/**
* @deprecated since 2.6
*/
@Deprecated // since 2.6
public CollectionSerializer(JavaType elemType, boolean staticTyping, TypeSerializer vts,
BeanProperty property, JsonSerializer<Object> valueSerializer) {
// note: assumption is 'property' is always passed as null
this(elemType, staticTyping, vts, valueSerializer);
}
public CollectionSerializer(CollectionSerializer src,
BeanProperty property, TypeSerializer vts, JsonSerializer<?> valueSerializer,
Boolean unwrapSingle) {
super(src, property, vts, valueSerializer, unwrapSingle);
}
@Override
public ContainerSerializer<?> _withValueTypeSerializer(TypeSerializer vts) {
return new CollectionSerializer(this, _property, vts, _elementSerializer, _unwrapSingle);
}
@Override
public CollectionSerializer withResolved(BeanProperty property,
TypeSerializer vts, JsonSerializer<?> elementSerializer,
Boolean unwrapSingle) {
return new CollectionSerializer(this, property, vts, elementSerializer, unwrapSingle);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public boolean isEmpty(SerializerProvider prov, Collection<?> value) {
return (value == null) || value.isEmpty();
}
@Override
public boolean hasSingleElement(Collection<?> value) {
Iterator<?> it = value.iterator();
if (!it.hasNext()) {
return false;
}
it.next();
return !it.hasNext();
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
/**
* Special bogus "serializer" that will throw
* {@link JsonMappingException} if an attempt is made to deserialize
* a value. This is used as placeholder to avoid NPEs for uninitialized
* structured serializers or handlers.
*/
public class FailingDeserializer extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
protected final String _message;
public FailingDeserializer(String m) {
super(Object.class);
_message = m;
}
@Override
public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws JsonMappingException{
throw ctxt.mappingException(_message);
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.impl.*;
import com.fasterxml.jackson.databind.util.NameTransformer;
import com.fasterxml.jackson.databind.util.TokenBuffer;
/**
* Deserializer class that can deserialize instances of
* arbitrary bean objects, usually from JSON Object structs,
*/
public class BeanDeserializer
extends BeanDeserializerBase
implements java.io.Serializable
{
/* TODOs for future versions:
*
* For 2.7?
*
* - New method in JsonDeserializer (deserializeNext()) to allow use of more
* efficient 'nextXxx()' method `JsonParser` provides.
*
* Also: need to ensure efficient impl of those methods for Smile, CBOR
* at least (in addition to JSON)
*/
private static final long serialVersionUID = 1L;
/*
/**********************************************************
/* Life-cycle, construction, initialization
/**********************************************************
*/
/**
* Constructor used by {@link BeanDeserializerBuilder}.
*/
public BeanDeserializer(BeanDeserializerBuilder builder, BeanDescription beanDesc,
BeanPropertyMap properties, Map<String, SettableBeanProperty> backRefs,
HashSet<String> ignorableProps, boolean ignoreAllUnknown,
boolean hasViews)
{
super(builder, beanDesc, properties, backRefs,
ignorableProps, ignoreAllUnknown, hasViews);
}
/**
* Copy-constructor that can be used by sub-classes to allow
* copy-on-write style copying of settings of an existing instance.
*/
protected BeanDeserializer(BeanDeserializerBase src) {
super(src, src._ignoreAllUnknown);
}
protected BeanDeserializer(BeanDeserializerBase src, boolean ignoreAllUnknown) {
super(src, ignoreAllUnknown);
}
protected BeanDeserializer(BeanDeserializerBase src, NameTransformer unwrapper) {
super(src, unwrapper);
}
public BeanDeserializer(BeanDeserializerBase src, ObjectIdReader oir) {
super(src, oir);
}
public BeanDeserializer(BeanDeserializerBase src, HashSet<String> ignorableProps) {
super(src, ignorableProps);
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper)
{
/* bit kludgy but we don't want to accidentally change type; sub-classes
* MUST override this method to support unwrapped properties...
*/
if (getClass() != BeanDeserializer.class) {
return this;
}
/* main thing really is to just enforce ignoring of unknown
* properties; since there may be multiple unwrapped values
* and properties for all may be interleaved...
*/
return new BeanDeserializer(this, unwrapper);
}
@Override
public BeanDeserializer withObjectIdReader(ObjectIdReader oir) {
return new BeanDeserializer(this, oir);
}
@Override
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.util;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
import com.fasterxml.jackson.databind.type.ClassKey;
/**
* Helper class for caching resolved root names.
*/
public class RootNameLookup implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* For efficient operation, let's try to minimize number of times we
* need to introspect root element name to use.
*/
protected transient LRUMap<ClassKey,PropertyName> _rootNames;
public RootNameLookup() {
_rootNames = new LRUMap<ClassKey,PropertyName>(20, 200);
}
public PropertyName findRootName(JavaType rootType, MapperConfig<?> config) {
return findRootName(rootType.getRawClass(), config);
}
public PropertyName findRootName(Class<?> rootType, MapperConfig<?> config)
{
ClassKey key = new ClassKey(rootType);
PropertyName name = _rootNames.get(key);
if (name != null) {
return name;
}
BeanDescription beanDesc = config.introspectClassAnnotations(rootType);
AnnotationIntrospector intr = config.getAnnotationIntrospector();
AnnotatedClass ac = beanDesc.getClassInfo();
name = intr.findRootName(ac);
// No answer so far? Let's just default to using simple class name
if (name == null || !name.hasSimpleName()) {
// Should we strip out enclosing class tho? For now, nope:
name = PropertyName.construct(rootType.getSimpleName());
}
_rootNames.put(key, name);
return name;
}
/*
/**********************************************************
/* Serializable overrides
/**********************************************************
*/
/**
* Need to override to reproduce cache object via constructor, instead
* of serialize/deserialize (since we do NOT want to retain cached data)
*/
protected Object readResolve() {
return new RootNameLookup();
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId;
/**
* Exception thrown during deserialization when there are object id that can't
* be resolved.
*
* @author pgelinas
*/
public final class UnresolvedForwardReference extends JsonMappingException {
private static final long serialVersionUID = 1L;
private ReadableObjectId _roid;
private List<UnresolvedId> _unresolvedIds;
public UnresolvedForwardReference(String msg, JsonLocation loc, ReadableObjectId roid)
{
super(msg, loc);
_roid = roid;
}
public UnresolvedForwardReference(String msg)
{
super(msg);
_unresolvedIds = new ArrayList<UnresolvedId>();
}
// ******************************
// ****** Accessor methods ******
// ******************************
public ReadableObjectId getRoid() {
return _roid;
}
public Object getUnresolvedId() {
return _roid.getKey().key;
}
public void addUnresolvedId(Object id, Class<?> type, JsonLocation where) {
_unresolvedIds.add(new UnresolvedId(id, type, where));
}
public List<UnresolvedId> getUnresolvedIds(){
return _unresolvedIds;
}
@Override
public String getMessage()
{
String msg = super.getMessage();
if (_unresolvedIds == null) {
return msg;
}
StringBuilder sb = new StringBuilder(msg);
Iterator<UnresolvedId> iterator = _unresolvedIds.iterator();
while (iterator.hasNext()) {
UnresolvedId unresolvedId = iterator.next();
sb.append(unresolvedId.toString());
if (iterator.hasNext()) {
sb.append(", ");
}
}
sb.append('.');
return sb.toString();
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.format.InputAccessor;
import com.fasterxml.jackson.core.format.MatchStrength;
/**
* Sub-class of {@link JsonFactory} that will create a proper
* {@link ObjectCodec} to allow seam-less conversions between
* JSON content and Java objects (POJOs).
* The only addition to regular {@link JsonFactory} currently
* is that {@link ObjectMapper} is constructed and passed as
* the codec to use.
*/
public class MappingJsonFactory
extends JsonFactory
{
// generated for Jackson 2.1.0
private static final long serialVersionUID = -6744103724013275513L;
public MappingJsonFactory()
{
this(null);
}
public MappingJsonFactory(ObjectMapper mapper)
{
super(mapper);
if (mapper == null) {
setCodec(new ObjectMapper(this));
}
}
/**
* We'll override the method to return more specific type; co-variance
* helps here
*/
@Override
public final ObjectMapper getCodec() { return (ObjectMapper) _objectCodec; }
// @since 2.1
@Override
public JsonFactory copy()
{
_checkInvalidCopy(MappingJsonFactory.class);
// note: as with base class, must NOT copy mapper reference
return new MappingJsonFactory(null);
}
/*
/**********************************************************
/* Format detection functionality (since 1.8)
/**********************************************************
*/
/**
* Sub-classes need to override this method (as of 1.8)
*/
@Override
public String getFormatName()
{
/* since non-JSON factories typically should not extend this class,
* let's just always return JSON as name.
*/
return FORMAT_NAME_JSON;
}
/**
* Sub-classes need to override this method (as of 1.8)
*/
@Override
public MatchStrength hasFormat(InputAccessor acc) throws IOException
{
if (getClass() == MappingJsonFactory.class) {
return hasJSONFormat(acc);
}
return null;
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.reflect.*;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeBindings;
import com.fasterxml.jackson.databind.util.ClassUtil;
public final class AnnotatedConstructor
extends AnnotatedWithParams
{
private static final long serialVersionUID = 1L;
protected final Constructor<?> _constructor;
/**
* Field that is used to make JDK serialization work with this
* object.
*
* @since 2.1
*/
protected Serialization _serialization;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public AnnotatedConstructor(AnnotatedClass ctxt, Constructor<?> constructor,
AnnotationMap classAnn, AnnotationMap[] paramAnn)
{
super(ctxt, classAnn, paramAnn);
if (constructor == null) {
throw new IllegalArgumentException("Null constructor not allowed");
}
_constructor = constructor;
}
/**
* Method used for JDK serialization support
* @since 2.1
*/
protected AnnotatedConstructor(Serialization ser)
{
super(null, null, null);
_constructor = null;
_serialization = ser;
}
@Override
public AnnotatedConstructor withAnnotations(AnnotationMap ann) {
return new AnnotatedConstructor(_context, _constructor, ann, _paramAnnotations);
}
/*
/**********************************************************
/* Annotated impl
/**********************************************************
*/
@Override
public Constructor<?> getAnnotated() { return _constructor; }
@Override
public int getModifiers() { return _constructor.getModifiers(); }
@Override
public String getName() { return _constructor.getName(); }
@Override
public Type getGenericType() {
return getRawType();
}
@Override
public Class<?> getRawType() {
return _constructor.getDeclaringClass();
}
// note: copied verbatim from AnnotatedMethod; hard to generalize
/**
* As per [JACKSON-468], we need to also allow declaration of local
* type bindings; mostly it will allow defining bounds.
*/
@Override
public JavaType getType(TypeBindings bindings)
{
return getType(bindings, _constructor.getTypeParameters());
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
@Override
public int getParameterCount() {
return _constructor.getParameterTypes().length;
}
@Override
public Class<?> getRawParameterType(int index)
{
Class<?>[] types = _constructor.getParameterTypes();
return (index >= types.length) ? null : types[index];
}
@Override
public Type getGenericParameterType(int index)
{
Type[] types = _constructor.getGenericParameterTypes();
return (index >= types.length) ? null : types[index];
}
@Override
public final Object call() throws Exception {
return _constructor.newInstance();
}
@Override
public final Object call(Object[] args) throws Exception {
return _constructor.
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>newInstance(args);
}
@Override
public final Object call1(Object arg) throws Exception {
return _constructor.newInstance(arg);
}
/*
/**********************************************************
/* AnnotatedMember impl
/**********************************************************
*/
@Override
public Class<?> getDeclaringClass() { return _constructor.getDeclaringClass(); }
@Override
public Member getMember() { return _constructor; }
@Override
public void setValue(Object pojo, Object value)
throws UnsupportedOperationException
{
throw new UnsupportedOperationException("Cannot call setValue() on constructor of "
+getDeclaringClass().getName());
}
@Override
public Object getValue(Object pojo)
throws UnsupportedOperationException
{
throw new UnsupportedOperationException("Cannot call getValue() on constructor of "
+getDeclaringClass().getName());
}
/*
/**********************************************************
/* Extended API, specific annotations
/**********************************************************
*/
@Override
public String toString() {
return "[constructor for "+getName()+", annotations: "+_annotations+"]";
}
@Override
public int hashCode() {
return _constructor.getName().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
return ((AnnotatedConstructor) o)._constructor == _constructor;
}
/*
/**********************************************************
/* JDK serialization handling
/**********************************************************
*/
Object writeReplace() {
return new AnnotatedConstructor(new Serialization(_constructor));
}
Object readResolve() {
Class<?> clazz = _serialization.clazz;
try {
Constructor<?> ctor = clazz.getDeclaredConstructor(_serialization.args);
// 06-Oct-2012, tatu: Has "lost" its security override, must force back
if (!ctor.isAccessible()) {
ClassUtil.checkAndFixAccess(ctor);
}
return new AnnotatedConstructor(null, ctor, null, null);
} catch (Exception e) {
throw new IllegalArgumentException("Could not find constructor with "
+_serialization.args.length+" args from Class '"+clazz.getName());
}
}
/**
* Helper class that is used as the workaround to persist
* Field references. It basically just stores declaring class
* and field name.
*/
private final static class Serialization
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected Class<?> clazz;
protected Class<?>[] args;
public Serialization(Constructor<?> ctor) {
clazz = ctor.getDeclaringClass();
args = ctor.getParameterTypes();
}
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.net.URL;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
import com.fasterxml.jackson.core.Base64Variant;
import com.fasterxml.jackson.core.FormatSchema;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonPointer;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
import com.fasterxml.jackson.core.filter.FilteringParserDelegate;
import com.fasterxml.jackson.core.filter.JsonPointerBasedFilter;
import com.fasterxml.jackson.core.filter.TokenFilter;
import com.fasterxml.jackson.core.type.ResolvedType;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.cfg.ContextAttributes;
import com.fasterxml.jackson.databind.deser.DataFormatReaders;
import com.fasterxml.jackson.databind.deser.DefaultDeserializationContext;
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.NullNode;
import com.fasterxml.jackson.databind.node.TreeTraversingParser;
import com.fasterxml.jackson.databind.type.SimpleType;
import com.fasterxml.jackson.databind.type.TypeFactory;
/**
* Builder object that can be used for per-serialization configuration of
* deserialization parameters, such as root type to use or object
* to update (instead of constructing new instance).
*<p>
* Uses "mutant factory" pattern so that instances are immutable
* (and thus fully thread-safe with no external synchronization);
* new instances are constructed for different configurations.
* Instances are initially constructed by {@link ObjectMapper} and can be
* reused, shared, cached; both because of thread-safety and because
* instances are relatively light-weight.
*/
public class ObjectReader
extends ObjectCodec
implements Versioned, java.io.Serializable // since 2.1
{
private static final long serialVersionUID = 1L; // since
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>dataFormatReaders;
if (det != null) {
det = det.withType(valueType);
}
return _new(this, _config, valueType, rootDeser,
_valueToUpdate, _schema, _injectableValues, det);
}
/**
* Method for constructing a new reader instance that is configured
* to data bind into specified type.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.5
*/
public ObjectReader forType(Class<?> valueType) {
return forType(_config.constructType(valueType));
}
/**
* Method for constructing a new reader instance that is configured
* to data bind into specified type.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.5
*/
public ObjectReader forType(TypeReference<?> valueTypeRef) {
return forType(_config.getTypeFactory().constructType(valueTypeRef.getType()));
}
/**
* @deprecated since 2.5 Use {@link #forType(JavaType)} instead
*/
@Deprecated
public ObjectReader withType(JavaType valueType) {
return forType(valueType);
}
/**
* @deprecated since 2.5 Use {@link #forType(Class)} instead
*/
@Deprecated
public ObjectReader withType(Class<?> valueType) {
return forType(_config.constructType(valueType));
}
/**
* @deprecated since 2.5 Use {@link #forType(Class)} instead
*/
@Deprecated
public ObjectReader withType(java.lang.reflect.Type valueType) {
return forType(_config.getTypeFactory().constructType(valueType));
}
/**
* @deprecated since 2.5 Use {@link #forType(TypeReference)} instead
*/
@Deprecated
public ObjectReader withType(TypeReference<?> valueTypeRef) {
return forType(_config.getTypeFactory().constructType(valueTypeRef.getType()));
}
/**
* Method for constructing a new instance with configuration that
* updates passed Object (as root value), instead of constructing
* a new value.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*/
public ObjectReader withValueToUpdate(Object value)
{
if (value == _valueToUpdate) return this;
if (value == null) {
throw new IllegalArgumentException("cat not update null value");
}
JavaType t;
/* no real benefit from pre-fetching, as updating readers are much
* less likely to be reused, and value type may also be forced
* with a later chained call...
*/
if (_valueType == null) {
t = _config.constructType(value.getClass());
} else {
t = _valueType;
}
return _new
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.util;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import java.lang.reflect.Method;
import java.util.*;
/**
* Helper class used to resolve String values (either JSON Object field
* names or regular String values) into Java Enum instances.
*/
public class EnumResolver implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected final Class<Enum<?>> _enumClass;
protected final Enum<?>[] _enums;
protected final HashMap<String, Enum<?>> _enumsById;
protected EnumResolver(Class<Enum<?>> enumClass, Enum<?>[] enums, HashMap<String, Enum<?>> map)
{
_enumClass = enumClass;
_enums = enums;
_enumsById = map;
}
/**
* Factory method for constructing resolver that maps from Enum.name() into
* Enum value
*/
public static EnumResolver constructFor(Class<Enum<?>> enumCls, AnnotationIntrospector ai)
{
Enum<?>[] enumValues = enumCls.getEnumConstants();
if (enumValues == null) {
throw new IllegalArgumentException("No enum constants for class "+enumCls.getName());
}
HashMap<String, Enum<?>> map = new HashMap<String, Enum<?>>();
for (Enum<?> e : enumValues) {
map.put(ai.findEnumValue(e), e);
}
return new EnumResolver(enumCls, enumValues, map);
}
/**
* Factory method for constructing resolver that maps from Enum.toString() into
* Enum value
*/
public static EnumResolver constructUsingToString(Class<Enum<?>> enumCls)
{
Enum<?>[] enumValues = enumCls.getEnumConstants();
HashMap<String, Enum<?>> map = new HashMap<String, Enum<?>>();
// from last to first, so that in case of duplicate values, first wins
for (int i = enumValues.length; --i >= 0; ) {
Enum<?> e = enumValues[i];
map.put(e.toString(), e);
}
return new EnumResolver(enumCls, enumValues, map);
}
public static EnumResolver constructUsingMethod(Class<Enum<?>> enumCls,
Method accessor)
{
Enum<?>[] enumValues = enumCls.getEnumConstants();
HashMap<String, Enum<?>> map = new HashMap<String, Enum<?>>();
// from last to first, so that in case of duplicate values, first wins
for (int i = enumValues.length; --i >= 0; ) {
Enum<?> en = enumValues[i];
try {
Object o = accessor.invoke(en);
if (o != null) {
map.put(o.toString(), en);
}
} catch (Exception e) {
throw new IllegalArgumentException("Failed to access @JsonValue of Enum value "+en+": "+e.getMessage());
}
}
return new EnumResolver(enumCls, enumValues, map);
}
/**
* This method is needed because of the dynamic nature of constructing
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
import com.fasterxml.jackson.databind.introspect.AnnotatedWithParams;
/**
* Default {@link ValueInstantiator} implementation, which supports
* Creator methods that can be indicated by standard Jackson
* annotations.
*/
@JacksonStdImpl
public class StdValueInstantiator
extends ValueInstantiator
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Type of values that are instantiated; used
* for error reporting purposes.
*/
protected final String _valueTypeDesc;
// // // Default (no-args) construction
/**
* Default (no-argument) constructor to use for instantiation
* (with {@link #createUsingDefault})
*/
protected AnnotatedWithParams _defaultCreator;
// // // With-args (property-based) construction
protected AnnotatedWithParams _withArgsCreator;
protected SettableBeanProperty[] _constructorArguments;
// // // Delegate construction
protected JavaType _delegateType;
protected AnnotatedWithParams _delegateCreator;
protected SettableBeanProperty[] _delegateArguments;
// // // Scalar construction
protected AnnotatedWithParams _fromStringCreator;
protected AnnotatedWithParams _fromIntCreator;
protected AnnotatedWithParams _fromLongCreator;
protected AnnotatedWithParams _fromDoubleCreator;
protected AnnotatedWithParams _fromBooleanCreator;
// // // Incomplete creator
protected AnnotatedParameter _incompleteParameter;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public StdValueInstantiator(DeserializationConfig config, Class<?> valueType) {
_valueTypeDesc = (valueType == null) ? "UNKNOWN TYPE" : valueType.getName();
}
public StdValueInstantiator(DeserializationConfig config, JavaType valueType) {
_valueTypeDesc = (valueType == null) ? "UNKNOWN TYPE" : valueType.toString();
}
/**
* Copy-constructor that sub-classes can use when creating new instances
* by fluent-style construction
*/
protected StdValueInstantiator(StdValueInstantiator src)
{
_valueTypeDesc = src._valueTypeDesc;
_defaultCreator = src._defaultCreator;
_constructorArguments = src._constructorArguments;
_withArgsCreator = src._withArgsCreator;
_delegateType = src._delegateType;
_delegateCreator = src._delegateCreator;
_delegateArguments = src._delegateArguments;
_fromStringCreator = src._fromStringCreator;
_fromIntCreator = src._fromIntCreator;
_fromLongCreator = src._fromLongCreator;
_fromDoubleCreator = src._fromDoubleCreator;
_fromBooleanCreator = src._fromBooleanCreator;
}
/**
* Method for setting properties related to
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.cfg;
import java.text.DateFormat;
import java.util.Locale;
import java.util.TimeZone;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.core.Base64Variant;
import com.fasterxml.jackson.core.SerializableString;
import com.fasterxml.jackson.core.io.SerializedString;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.ClassIntrospector;
import com.fasterxml.jackson.databind.introspect.VisibilityChecker;
import com.fasterxml.jackson.databind.jsontype.SubtypeResolver;
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.type.TypeBindings;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.ClassUtil;
/**
* Interface that defines functionality accessible through both
* serialization and deserialization configuration objects;
* accessors to mode-independent configuration settings
* and such.
* In addition, shared features are defined
* in {@link MapperFeature}.
*<p>
* Small part of implementation is included here by aggregating
* {@link BaseSettings} instance that contains configuration
* that is shared between different types of instances.
*/
public abstract class MapperConfig<T extends MapperConfig<T>>
implements ClassIntrospector.MixInResolver,
java.io.Serializable
{
private static final long serialVersionUID = 1L; // since 2.5
/**
* Set of shared mapper features enabled.
*/
protected final int _mapperFeatures;
/**
* Immutable container object for simple configuration settings.
*/
protected final BaseSettings _base;
/*
/**********************************************************
/* Life-cycle: constructors
/**********************************************************
*/
protected MapperConfig(BaseSettings base, int mapperFeatures)
{
_base = base;
_mapperFeatures = mapperFeatures;
}
protected MapperConfig(MapperConfig<T> src, int mapperFeatures)
{
_base = src._base;
_mapperFeatures = mapperFeatures;
}
protected MapperConfig(MapperConfig<T> src, BaseSettings base)
{
_base = base;
_mapperFeatures = src._mapperFeatures;
}
protected MapperConfig(MapperConfig<T> src)
{
_base = src._base;
_mapperFeatures = src._mapperFeatures;
}
/**
* Method that calculates bit set (flags) of all features that
* are enabled by default.
*/
public static <F extends Enum<F> & ConfigFeature> int collectFeatureDefaults(Class<F> enumClass)
{
int flags = 0;
for (F value : enumClass.getEnumConstants
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.type.ReferenceType;
// Since 2.6 in its own class
public class AtomicReferenceSerializer
extends StdSerializer<AtomicReference<?>>
{
private static final long serialVersionUID = 1L;
/**
* @deprecated Since 2.6
*/
@Deprecated
public AtomicReferenceSerializer() { super(AtomicReference.class, false); }
public AtomicReferenceSerializer(ReferenceType type) {
super(type);
}
@Override
public boolean isEmpty(SerializerProvider provider, AtomicReference<?> value) {
return (value == null) || (value.get() == null);
}
@Override
public void serialize(AtomicReference<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException {
provider.defaultSerializeValue(value.get(), jgen);
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("any", true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
visitor.expectAnyFormat(typeHint);
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.util;
/**
* Helper class used for checking whether a property is visible
* in the active view
*/
public class ViewMatcher implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected final static ViewMatcher EMPTY = new ViewMatcher();
public boolean isVisibleForView(Class<?> activeView) { return false; }
public static ViewMatcher construct(Class<?>[] views)
{
if (views == null) {
return EMPTY;
}
switch (views.length) {
case 0:
return EMPTY;
case 1:
return new Single(views[0]);
}
return new Multi(views);
}
/*
/**********************************************************
/* Concrete sub-classes
/**********************************************************
*/
private final static class Single extends ViewMatcher
{
private static final long serialVersionUID = 1L;
private final Class<?> _view;
public Single(Class<?> v) { _view = v; }
@Override
public boolean isVisibleForView(Class<?> activeView) {
return (activeView == _view) || _view.isAssignableFrom(activeView);
}
}
private final static class Multi extends ViewMatcher
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
private final Class<?>[] _views;
public Multi(Class<?>[] v) { _views = v; }
@Override
public boolean isVisibleForView(Class<?> activeView)
{
for (int i = 0, len = _views.length; i < len; ++i) {
Class<?> view = _views[i];
if ((activeView == view) || view.isAssignableFrom(activeView)) {
return true;
}
}
return false;
}
}
}
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import java.lang.annotation.Annotation;
import java.util.*;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.util.Converter;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Abstract class that defines API used for introspecting annotation-based
* configuration for serialization and deserialization. Separated
* so that different sets of annotations can be supported, and support
* plugged-in dynamically.
*<p>
* NOTE: due to rapid addition of new methods (and changes to existing methods),
* it is <b>strongly</b> recommended that custom implementations should not directly
* extend this class, but rather extend {@link NopAnnotationIntrospector}.
* This way added methods will not break backwards compatibility of custom annotation
* introspectors.
*/
@SuppressWarnings("serial")
public abstract class AnnotationIntrospector
implements Versioned, java.io.Serializable
{
/*
/**********************************************************
/* Helper types
/**********************************************************
*/
/**
* Value type used with managed and back references; contains type and
* logic name, used to link related references
*/
public static class ReferenceProperty
{
public enum Type {
/**
* Reference property that Jackson manages and that is serialized normally (by serializing
* reference object), but is used for resolving back references during
* deserialization.
* Usually this can be defined by using
* {@link com.fasterxml.jackson.annotation.JsonManagedReference}
*/
MANAGED_REFERENCE
/**
* Reference property that Jackson manages by suppressing it during serialization,
* and reconstructing during deserialization.
* Usually this can be defined by using
* {@link com.fasterxml.jackson.annotation.JsonBackReference}
*/
,BACK_REFERENCE
;
}
private final Type _type;
private final String _name;
public ReferenceProperty(Type t, String n) {
_type = t;
_name = n;
}
public
JacksonDatabind, 26
<FILEB>
<CHANGES>
implements BeanProperty,
java.io.Serializable // since 2.6.2
<CHANGEE>
<CHANGES>
private static final long serialVersionUID = 4603296144163950020L;
<CHANGEE>
<FILEE>
<FILEB>
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.Annotations;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Base bean property handler class, which implements common parts of
* reflection-based functionality for accessing a property value
* and serializing it.
*<p>
* Note that current design tries to keep instances immutable (semi-functional
* style); mostly because these instances are exposed to application
* code and this is to reduce likelihood of data corruption and
* synchronization issues.
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
<CHANGES>
implements BeanProperty
<CHANGEE>
{
// as of 2.6.2
<CHANGES>
<CHANGEE>
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;
/**
* Marker we use to indicate case where we have done format lookup,
* but found nothing; marker used to avoid having to repeat such lookups.
*
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();
/*
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.BeanDeserializer;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Deserializer that builds on basic {@link BeanDeserializer} but
* override some aspects like instance construction.
*/
public class ThrowableDeserializer
extends BeanDeserializer
{
private static final long serialVersionUID = 1L;
protected final static String PROP_NAME_MESSAGE = "message";
/*
/************************************************************
/* Construction
/************************************************************
*/
public ThrowableDeserializer(BeanDeserializer baseDeserializer) {
super(baseDeserializer);
// need to disable this, since we do post-processing
_vanillaProcessing = false;
}
/**
* Alternative constructor used when creating "unwrapping" deserializers
*/
protected ThrowableDeserializer(BeanDeserializer src, NameTransformer unwrapper) {
super(src, unwrapper);
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper) {
if (getClass() != ThrowableDeserializer.class) {
return this;
}
/* main thing really is to just enforce ignoring of unknown
* properties; since there may be multiple unwrapped values
* and properties for all may be interleaved...
*/
return new ThrowableDeserializer(this, unwrapper);
}
/*
/************************************************************
/* Overridden methods
/************************************************************
*/
@Override
public Object deserializeFromObject(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// 30-Sep-2010, tatu: Need to allow use of @JsonCreator, so:
if (_propertyBasedCreator != null) { // proper @JsonCreator
return _deserializeUsingPropertyBased(jp, ctxt);
}
if (_delegateDeserializer != null) {
return _valueInstantiator.createUsingDelegate(ctxt,
_delegateDeserializer.deserialize(jp, ctxt));
}
if (_beanType.isAbstract()) { // for good measure, check this too
throw JsonMappingException.from(jp, "Can not instantiate abstract type "+_beanType
+" (need to add/enable type information?)");
}
boolean hasStringCreator = _valueInstantiator.canCreateFromString();
boolean hasDefaultCtor = _valueInstantiator.canCreateUsingDefault();
// and finally, verify we do have single-String arg constructor (if no @JsonCreator)
if (!hasStringCreator && !hasDefaultCtor) {
throw new JsonMappingException("Can not deserialize Throwable of type "+_beanType
+" without having a default contructor, a single-String-arg constructor; or explicit @JsonCreator");
}
Object throwable = null;
Object[] pending = null;
int pendingIx = 0;
for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken())